Skip to content

Support running native process outside sandbox#724

Open
JaewonHur wants to merge 2 commits intoapple:mainfrom
JaewonHur:native-process
Open

Support running native process outside sandbox#724
JaewonHur wants to merge 2 commits intoapple:mainfrom
JaewonHur:native-process

Conversation

@JaewonHur
Copy link
Copy Markdown
Contributor

This PR supports NativeProcess, which runs outside of containerized environment. NativeProcess is managed the same as ManagedProcess, except it is spawned directly by vminitd (not vexec). These processes run outside of container namespaces, and no resources shared with container, invisible to it.

LinuxProcess with `native` property runs outside containerized
environment.
Comment on lines +853 to +855
for process in state.vendedProcesses.values where process.native {
try await process.kill(signal)
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't they call kill on the LinuxProcess they get back from exec?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the SandboxService.stop source code, I assumed it's the responsibility of LinuxContainer to clean up processes in VM. SandboxService.stop doesn't kill each process, but just kill container. Then, LinuxContainer kills the init process only, and it's up to the init process whether or not to kill other processes as well (as all others are parented to init process).

But, it's different for native process as it is not under container init process, but directly the child of vminitd. So, I guess for LinuxContainer.kill to be self-confined, it should kill native process as well.

My guess was:

  • Container's init process is responsible for other processes in container (that's why LinuxContainer.kill only kills that init process).
  • vminitd is responsible for that init process, and also native processes (that's why I think LinuxContainer.kill should kill native processes as well.

Copy link
Copy Markdown
Member

@dcantah dcantah May 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is, you can send ANY signal in kill. The signal doesn't always lead to the container dying. You can send sigwinch if you wanted, which delivering that signal to any native processes might be wrong.

Comment thread Sources/Containerization/LinuxContainer.swift
Comment on lines +17 to +34
public struct CreateProcessOptions: Sendable, Codable {
/// The process is created outside containerized env.
public var native: Bool

enum CodingKeys: String, CodingKey {
case native
}

public init(native: Bool) {
self.native = native
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

native = try container.decodeIfPresent(Bool.self, forKey: .native) ?? false
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The createProcess API takes in an optional containerID. This is what I was going to use to signify that we'd want to run a process in the root of the VM. e.g. supplying a nil containerID.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer we don't introduce new public API like this without really thinking through it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I forgot. Yeah let me update.
Do you think NativeProcess should live outside of ManagedContainer?

This will need reimplementing bookkeeping structure and management logic for NativeProcess.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think NativeProcess should live outside of ManagedContainer?

Whatever you think is right. If it feels too much hassle let me know

NativeProcess is a ContainerProcess that runs outside the containerized
environment. It's equally managed like the other ManagedProcess, but only
runs outside sandbox.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants