cubeBackendForPlatform function
Picks the backend for host platform os, bound to a run's context.
Kernel execution always goes through this constructor path —
SandboxedShell passes the real spec/workspace/tmpdir/env — while bare
cubeBackendForPlatform(os) calls (display, capability checks) get
inert defaults. Mapping: macos → sandbox-exec, linux → unshare,
windows → the Job Object descriptor (not enforcing), anything else →
the no-op backend.
Implementation
CubeSandboxBackend cubeBackendForPlatform(
String os, {
CubeSpec spec = const CubeSpec(name: 'host'),
String workspaceRoot = '/workspace',
String tmpdir = '/tmp',
Map<String, String> envVars = const {},
}) {
return switch (os) {
'macos' => MacOsSandboxBackend(
workspaceRoot: workspaceRoot,
tmpdir: tmpdir,
envVars: envVars,
),
'linux' => LinuxUnshareBackend(
spec: spec,
workspaceRoot: workspaceRoot,
tmpdir: tmpdir,
envVars: envVars,
),
'windows' => const WindowsJobBackend(),
_ => const NoOpCubeBackend(),
};
}