( config: SandboxConfig, nodeArgs: string[] = [], cliConfig?: Config, )
| 183 | } |
| 184 | |
| 185 | export 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[] = []; |
no test coverage detected