cubeBackendForPlatform function

CubeSandboxBackend cubeBackendForPlatform(
  1. String os, {
  2. CubeSpec spec = const CubeSpec(name: 'host'),
  3. String workspaceRoot = '/workspace',
  4. String tmpdir = '/tmp',
  5. Map<String, String> envVars = const {},
})

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(),
  };
}