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';
|
2026-03-24 07:32:20 -07:00
|
|
|
import { WindowsSandboxManager } from '../sandbox/windows/WindowsSandboxManager.js';
|
2026-03-19 15:25:22 -07:00
|
|
|
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-25 17:54:45 +00:00
|
|
|
const modeConfig =
|
|
|
|
|
policyManager && approvalMode
|
|
|
|
|
? policyManager.getModeConfig(approvalMode)
|
|
|
|
|
: undefined;
|
2026-03-19 15:25:22 -07:00
|
|
|
|
|
|
|
|
if (sandbox?.enabled) {
|
2026-03-25 17:54:45 +00:00
|
|
|
if (os.platform() === 'win32' && sandbox?.command === 'windows-native') {
|
|
|
|
|
return new WindowsSandboxManager({
|
|
|
|
|
workspace,
|
|
|
|
|
modeConfig,
|
|
|
|
|
policyManager,
|
|
|
|
|
});
|
|
|
|
|
} else if (os.platform() === 'linux') {
|
2026-03-25 18:58:45 -07:00
|
|
|
return new LinuxSandboxManager({
|
|
|
|
|
workspace,
|
|
|
|
|
modeConfig,
|
|
|
|
|
policyManager,
|
|
|
|
|
});
|
2026-03-25 17:54:45 +00:00
|
|
|
} else if (os.platform() === 'darwin') {
|
2026-03-23 21:48:13 -07:00
|
|
|
return new MacOsSandboxManager({
|
|
|
|
|
workspace,
|
|
|
|
|
modeConfig,
|
|
|
|
|
policyManager,
|
|
|
|
|
});
|
2026-03-19 15:25:22 -07:00
|
|
|
}
|
|
|
|
|
return new LocalSandboxManager();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new NoopSandboxManager();
|
|
|
|
|
}
|