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,
|
2026-03-27 12:57:26 -04:00
|
|
|
type GlobalSandboxOptions,
|
2026-03-19 15:25:22 -07:00
|
|
|
} 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';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a sandbox manager based on the provided settings.
|
|
|
|
|
*/
|
|
|
|
|
export function createSandboxManager(
|
|
|
|
|
sandbox: SandboxConfig | undefined,
|
2026-03-27 12:57:26 -04:00
|
|
|
options: GlobalSandboxOptions,
|
2026-03-23 21:48:13 -07:00
|
|
|
approvalMode?: string,
|
2026-03-19 15:25:22 -07:00
|
|
|
): SandboxManager {
|
2026-03-27 12:57:26 -04:00
|
|
|
if (!options.modeConfig && options.policyManager && approvalMode) {
|
|
|
|
|
options.modeConfig = options.policyManager.getModeConfig(approvalMode);
|
|
|
|
|
}
|
2026-03-19 15:25:22 -07:00
|
|
|
|
|
|
|
|
if (sandbox?.enabled) {
|
2026-03-27 15:35:01 -07:00
|
|
|
if (os.platform() === 'win32') {
|
2026-03-27 12:57:26 -04:00
|
|
|
return new WindowsSandboxManager(options);
|
2026-03-25 17:54:45 +00:00
|
|
|
} else if (os.platform() === 'linux') {
|
2026-03-27 12:57:26 -04:00
|
|
|
return new LinuxSandboxManager(options);
|
2026-03-25 17:54:45 +00:00
|
|
|
} else if (os.platform() === 'darwin') {
|
2026-03-27 12:57:26 -04:00
|
|
|
return new MacOsSandboxManager(options);
|
2026-03-19 15:25:22 -07:00
|
|
|
}
|
2026-04-01 16:51:06 -07:00
|
|
|
return new LocalSandboxManager(options);
|
2026-03-19 15:25:22 -07:00
|
|
|
}
|
|
|
|
|
|
2026-04-01 16:51:06 -07:00
|
|
|
return new NoopSandboxManager(options);
|
2026-03-19 15:25:22 -07:00
|
|
|
}
|