MCPcopy Create free account
hub / github.com/anus-dev/ANUS / start_sandbox

Function start_sandbox

packages/cli/src/utils/sandbox.ts:185–815  ·  view source on GitHub ↗
(
  config: SandboxConfig,
  nodeArgs: string[] = [],
  cliConfig?: Config,
)

Source from the content-addressed store, hash-verified

183}
184
185export async function start_sandbox(
186 config: SandboxConfig,
187 nodeArgs: string[] = [],
188 cliConfig?: Config,
189) {
190 const patcher = new ConsolePatcher({
191 debugMode: cliConfig?.getDebugMode() || !!process.env['DEBUG'],
192 stderr: true,
193 });
194 patcher.patch();
195
196 try {
197 if (config.command === 'sandbox-exec') {
198 // disallow BUILD_SANDBOX
199 if (process.env['BUILD_SANDBOX']) {
200 console.error('ERROR: cannot BUILD_SANDBOX when using macOS Seatbelt');
201 process.exit(1);
202 }
203 const profile = (process.env['SEATBELT_PROFILE'] ??= 'permissive-open');
204 let profileFile = new URL(`sandbox-macos-${profile}.sb`, import.meta.url)
205 .pathname;
206 // if profile name is not recognized, then look for file under project settings directory
207 if (!BUILTIN_SEATBELT_PROFILES.includes(profile)) {
208 profileFile = path.join(
209 SETTINGS_DIRECTORY_NAME,
210 `sandbox-macos-${profile}.sb`,
211 );
212 }
213 if (!fs.existsSync(profileFile)) {
214 console.error(
215 `ERROR: missing macos seatbelt profile file '${profileFile}'`,
216 );
217 process.exit(1);
218 }
219 // Log on STDERR so it doesn't clutter the output on STDOUT
220 console.error(`using macos seatbelt (profile: ${profile}) ...`);
221 // if DEBUG is set, convert to --inspect-brk in NODE_OPTIONS
222 const nodeOptions = [
223 ...(process.env['DEBUG'] ? ['--inspect-brk'] : []),
224 ...nodeArgs,
225 ].join(' ');
226
227 const args = [
228 '-D',
229 `TARGET_DIR=${fs.realpathSync(process.cwd())}`,
230 '-D',
231 `TMP_DIR=${fs.realpathSync(os.tmpdir())}`,
232 '-D',
233 `HOME_DIR=${fs.realpathSync(os.homedir())}`,
234 '-D',
235 `CACHE_DIR=${fs.realpathSync(execSync(`getconf DARWIN_USER_CACHE_DIR`).toString().trim())}`,
236 ];
237
238 // Add included directories from the workspace context
239 // Always add 5 INCLUDE_DIR parameters to ensure .sb files can reference them
240 const MAX_INCLUDE_DIRS = 5;
241 const targetDir = fs.realpathSync(cliConfig?.getTargetDir() || '');
242 const includedDirs: string[] = [];

Callers 1

mainFunction · 0.85

Calls 12

patchMethod · 0.95
getContainerPathFunction · 0.85
portsFunction · 0.85
parseImageNameFunction · 0.85
entrypointFunction · 0.85
getDebugModeMethod · 0.80
getTargetDirMethod · 0.80
getWorkspaceContextMethod · 0.80
getDirectoriesMethod · 0.80
cleanupMethod · 0.45

Tested by

no test coverage detected