2026-03-19 15:25:22 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2026 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import os from 'node:os';
|
|
|
|
|
import {
|
|
|
|
|
type SandboxManager,
|
|
|
|
|
NoopSandboxManager,
|
|
|
|
|
LocalSandboxManager,
|
|
|
|
|
} from './sandboxManager.js';
|
|
|
|
|
import { LinuxSandboxManager } from '../sandbox/linux/LinuxSandboxManager.js';
|
|
|
|
|
import { MacOsSandboxManager } from '../sandbox/macos/MacOsSandboxManager.js';
|
|
|
|
|
import { WindowsSandboxManager } from './windowsSandboxManager.js';
|
|
|
|
|
import type { SandboxConfig } from '../config/config.js';
|
2026-03-23 21:48:13 -07:00
|
|
|
import { type SandboxPolicyManager } from '../policy/sandboxPolicyManager.js';
|
2026-03-19 15:25:22 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a sandbox manager based on the provided settings.
|
|
|
|
|
*/
|
|
|
|
|
export function createSandboxManager(
|
|
|
|
|
sandbox: SandboxConfig | undefined,
|
|
|
|
|
workspace: string,
|
2026-03-23 21:48:13 -07:00
|
|
|
policyManager?: SandboxPolicyManager,
|
|
|
|
|
approvalMode?: string,
|
2026-03-19 15:25:22 -07:00
|
|
|
): SandboxManager {
|
2026-03-23 21:48:13 -07:00
|
|
|
if (approvalMode === 'yolo') {
|
|
|
|
|
return new NoopSandboxManager();
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 15:25:22 -07:00
|
|
|
const isWindows = os.platform() === 'win32';
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
isWindows &&
|
|
|
|
|
(sandbox?.enabled || sandbox?.command === 'windows-native')
|
|
|
|
|
) {
|
2026-03-23 11:43:58 -04:00
|
|
|
return new WindowsSandboxManager({ workspace });
|
2026-03-19 15:25:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sandbox?.enabled) {
|
|
|
|
|
if (os.platform() === 'linux') {
|
|
|
|
|
return new LinuxSandboxManager({ workspace });
|
|
|
|
|
}
|
|
|
|
|
if (os.platform() === 'darwin') {
|
2026-03-23 21:48:13 -07:00
|
|
|
const modeConfig =
|
|
|
|
|
policyManager && approvalMode
|
|
|
|
|
? policyManager.getModeConfig(approvalMode)
|
|
|
|
|
: undefined;
|
|
|
|
|
return new MacOsSandboxManager({
|
|
|
|
|
workspace,
|
|
|
|
|
modeConfig,
|
|
|
|
|
policyManager,
|
|
|
|
|
});
|
2026-03-19 15:25:22 -07:00
|
|
|
}
|
|
|
|
|
return new LocalSandboxManager();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new NoopSandboxManager();
|
|
|
|
|
}
|