@causyne/agent 1.20.118 → 1.20.121

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/package.json +1 -1
  2. package/src/agent/errorClassifier.js +113 -0
  3. package/src/agent/errorClassifier.ts +161 -0
  4. package/src/agent/promptIntent.js +200 -0
  5. package/src/agent/promptIntent.ts +203 -0
  6. package/src/agent/toolArgValidator.js +97 -0
  7. package/src/agent/toolArgValidator.ts +112 -0
  8. package/src/agentLoop.js +51 -351
  9. package/src/agentLoop.ts +69 -363
  10. package/src/autoUpdate.js +111 -8
  11. package/src/autoUpdate.ts +144 -8
  12. package/src/browser/causyneBrowser.js +231 -136
  13. package/src/browser/causyneBrowser.ts +229 -140
  14. package/src/browser/searchProviders.js +41 -30
  15. package/src/browser/searchProviders.ts +24 -14
  16. package/src/browser/workspacePathSafety.js +50 -0
  17. package/src/browser/workspacePathSafety.ts +50 -0
  18. package/src/browser/workspacePreview.js +27 -4
  19. package/src/browser/workspacePreview.ts +28 -4
  20. package/src/cliMode.js +17 -3
  21. package/src/commands.js +15 -22
  22. package/src/config.js +42 -63
  23. package/src/configVault.js +204 -0
  24. package/src/configVault.ts +213 -0
  25. package/src/core/contextCompactor.js +70 -11
  26. package/src/core/contextCompactor.ts +83 -11
  27. package/src/creative/liveBridge.js +34 -1
  28. package/src/creative/liveBridge.ts +28 -1
  29. package/src/dynamicCatalogue.js +42 -73
  30. package/src/dynamicCatalogue.ts +74 -60
  31. package/src/entrypoint.js +77 -4
  32. package/src/headlessCli.js +304 -0
  33. package/src/headlessCli.ts +380 -0
  34. package/src/mcp/mcpClient.js +38 -11
  35. package/src/mcp/mcpClient.ts +44 -11
  36. package/src/mcp/mcpRegistry.js +2 -5
  37. package/src/mcp/mcpRegistry.ts +2 -5
  38. package/src/mcp/mcpSecurity.js +189 -0
  39. package/src/mcp/mcpSecurity.ts +190 -0
  40. package/src/observer/evidence.js +23 -0
  41. package/src/observer/evidence.ts +21 -0
  42. package/src/osKeychain.js +209 -0
  43. package/src/osKeychain.ts +245 -0
  44. package/src/providers/anthropic.js +61 -28
  45. package/src/providers/base.js +14 -0
  46. package/src/providers/byokHttp.js +354 -0
  47. package/src/providers/byokHttp.ts +454 -0
  48. package/src/providers/byokStream.js +657 -0
  49. package/src/providers/byokStream.ts +759 -0
  50. package/src/providers/dashscope-byok.js +47 -32
  51. package/src/providers/deepseek.js +43 -39
  52. package/src/providers/gemini.js +73 -38
  53. package/src/providers/moonshot.js +43 -33
  54. package/src/providers/muse.js +10 -10
  55. package/src/providers/ollama.js +46 -31
  56. package/src/providers/openai-compatible.js +57 -32
  57. package/src/providers/openrouter.js +77 -113
  58. package/src/providers/openrouter.ts +99 -118
  59. package/src/providers/qwen-byok.js +46 -23
  60. package/src/providers/toolContracts.js +9 -3
  61. package/src/providers/toolContracts.ts +9 -3
  62. package/src/providers/wireNormalizer.js +238 -0
  63. package/src/providers/wireNormalizer.ts +279 -0
  64. package/src/providers/xai.js +43 -33
  65. package/src/sandbox.js +77 -56
  66. package/src/sandboxPolicy.js +1208 -0
  67. package/src/sandboxPolicy.ts +1300 -0
  68. package/src/sessionJournal.js +47 -0
  69. package/src/sessionJournal.ts +49 -0
  70. package/src/tools/browserAutomator.js +13 -1
  71. package/src/tools/browserAutomator.ts +13 -0
  72. package/src/tools/creativeApps.js +2 -1
  73. package/src/tools/creativeApps.ts +2 -1
  74. package/src/tools/gameAssetFetcher.js +130 -26
  75. package/src/tools/gameAssetHarvester.js +80 -58
  76. package/src/tools/nativeEngine.js +1 -1
  77. package/src/tools/nativeEngine.ts +1 -1
  78. package/src/tools/osSandbox.js +473 -0
  79. package/src/tools/osSandbox.ts +554 -0
  80. package/src/tools/persistentShell.js +8 -3
  81. package/src/tools/registry.js +13 -0
  82. package/src/tools/subprocessEnv.js +197 -0
  83. package/src/tools/subprocessEnv.ts +212 -0
  84. package/src/tools/sysRun.js +39 -6
  85. package/src/tools/sysRun.ts +53 -7
  86. package/src/tools/toolScanner.js +596 -140
  87. package/src/tools/toolScanner.ts +665 -147
  88. package/src/tools/toolSelfRepair.js +243 -114
  89. package/src/tools/toolSelfRepair.ts +262 -111
  90. package/src/tools/webFetch.js +161 -24
  91. package/src/tools/webFetch.ts +157 -22
  92. package/src/tools/webSearch.js +33 -4
  93. package/src/tools/webSearch.ts +27 -4
  94. package/src/tui/sessionPicker.js +132 -35
  95. package/src/tui/sessionPicker.ts +153 -32
  96. package/src/tui/sessionPickerView.js +277 -34
  97. package/src/tui/sessionPickerView.ts +328 -34
  98. package/src/tui/statusLine.js +3 -0
  99. package/src/tui/statusLine.ts +5 -0
  100. package/src/tui/workspaceIdentity.js +133 -0
  101. package/src/tui/workspaceIdentity.ts +146 -0
@@ -324,7 +324,7 @@ export const nativeEngineTool = {
324
324
  parameters: {
325
325
  type: 'object',
326
326
  properties: {
327
- engine: { type: 'string', default: 'film', description: 'Engine id, default film. status lists installed engines.' },
327
+ engine: { type: 'string', description: 'Engine id, default film. status lists installed engines.' },
328
328
  action: { type: 'string', enum: [...ACTIONS] },
329
329
  command: { type: 'string', description: 'Command id for execute or describe.' },
330
330
  params: { type: 'object', description: 'Command parameters for execute.' },
@@ -0,0 +1,473 @@
1
+ /**
2
+ * Causyne Agent — OS-Level Process Sandboxing Wrapper (Sector 2B)
3
+ *
4
+ * Provides kernel-enforced filesystem & network isolation around shell tool
5
+ * subprocesses when enabled via `CAUSYNE_OS_SANDBOX` or `config.osSandbox`:
6
+ * - macOS (`darwin`): Apple Seatbelt (`/usr/bin/sandbox-exec -p <SBPL>`)
7
+ * - Linux (`linux`): Bubblewrap (`bwrap`) mount/network namespaces
8
+ * - Windows / nested containers: honest capability reporting (`backend: 'none'`)
9
+ * with fail-closed enforcement when `strict` mode is explicitly requested.
10
+ *
11
+ * Complements application-level `Sandbox` classification and `sanitizeSubprocessEnv`
12
+ * without ever stripping or degrading peer ACP capabilities.
13
+ */
14
+ import { spawnSync } from 'node:child_process';
15
+ import fs from 'node:fs';
16
+ import os from 'node:os';
17
+ import path from 'node:path';
18
+ const SEATBELT_BIN = '/usr/bin/sandbox-exec';
19
+ const CREDENTIAL_SUBPATHS = [
20
+ '.ssh',
21
+ '.aws',
22
+ '.gnupg',
23
+ '.kube',
24
+ '.causyne',
25
+ '.netrc',
26
+ '.git-credentials',
27
+ '.pypirc',
28
+ 'Library/Keychains'
29
+ ];
30
+ const SHELL_PERSISTENCE_FILES = [
31
+ '.bashrc',
32
+ '.bash_profile',
33
+ '.bash_login',
34
+ '.profile',
35
+ '.zshrc',
36
+ '.zprofile',
37
+ '.zshenv',
38
+ '.zlogin',
39
+ '.config/fish/config.fish'
40
+ ];
41
+ const DEV_CACHE_SUBPATHS = [
42
+ '.npm',
43
+ '.cache',
44
+ '.cargo',
45
+ '.rustup',
46
+ '.gradle',
47
+ '.m2',
48
+ 'go/pkg',
49
+ 'Library/Caches'
50
+ ];
51
+ let cachedProbe = null;
52
+ /**
53
+ * Escapes a filesystem path for safe embedding in an Apple Seatbelt SBPL string.
54
+ * Rejects control characters and NUL bytes to prevent S-expression injection.
55
+ */
56
+ export function escapeSeatbeltPath(rawPath) {
57
+ if (typeof rawPath !== 'string' || rawPath.length === 0)
58
+ return null;
59
+ for (let i = 0; i < rawPath.length; i++) {
60
+ const code = rawPath.charCodeAt(i);
61
+ if (code < 0x20 || code === 0x7f)
62
+ return null;
63
+ }
64
+ return rawPath.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
65
+ }
66
+ function resolveCanonicalPaths(rawPath) {
67
+ const resolved = path.resolve(rawPath);
68
+ const out = new Set([resolved]);
69
+ try {
70
+ const real = fs.realpathSync.native(resolved);
71
+ out.add(real);
72
+ }
73
+ catch {
74
+ // Walk up to nearest existing ancestor so symlinked prefixes (e.g. /var -> /private/var) resolve
75
+ let current = resolved;
76
+ const tail = [];
77
+ for (let depth = 0; depth < 64; depth++) {
78
+ const parent = path.dirname(current);
79
+ if (parent === current)
80
+ break;
81
+ tail.unshift(path.basename(current));
82
+ current = parent;
83
+ try {
84
+ const realAncestor = fs.realpathSync.native(current);
85
+ out.add(path.resolve(realAncestor, ...tail));
86
+ break;
87
+ }
88
+ catch {
89
+ continue;
90
+ }
91
+ }
92
+ }
93
+ return [...out];
94
+ }
95
+ function isSameOrChildPath(candidate, parent) {
96
+ const rel = path.relative(parent, candidate);
97
+ return rel === '' || (rel !== '..' && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel));
98
+ }
99
+ function workspaceOverlapsPath(workspacePaths, targetPath) {
100
+ const targetVariants = resolveCanonicalPaths(targetPath);
101
+ for (const ws of workspacePaths) {
102
+ const wsVariants = resolveCanonicalPaths(ws);
103
+ for (const wv of wsVariants) {
104
+ for (const tv of targetVariants) {
105
+ if (isSameOrChildPath(wv, tv))
106
+ return true;
107
+ }
108
+ }
109
+ }
110
+ return false;
111
+ }
112
+ /**
113
+ * Parses `CAUSYNE_OS_SANDBOX` / `config.osSandbox` into an explicit OS sandbox mode.
114
+ * Defaults to `'off'` unless explicitly enabled so standard workflows never break unexpectedly.
115
+ */
116
+ export function resolveOsSandboxMode(env = process.env, configMode) {
117
+ const raw = (typeof env.CAUSYNE_OS_SANDBOX === 'string' && env.CAUSYNE_OS_SANDBOX.trim())
118
+ ? env.CAUSYNE_OS_SANDBOX.trim()
119
+ : (typeof configMode === 'string' ? configMode.trim() : '');
120
+ const lower = raw.toLowerCase();
121
+ const networkEnv = typeof env.CAUSYNE_OS_SANDBOX_NETWORK === 'string'
122
+ ? env.CAUSYNE_OS_SANDBOX_NETWORK.trim().toLowerCase()
123
+ : '';
124
+ const allowNetwork = !(networkEnv === '0' || networkEnv === 'false' || networkEnv === 'off' || networkEnv === 'deny');
125
+ if (!lower || lower === 'off' || lower === '0' || lower === 'false' || lower === 'disabled') {
126
+ return { mode: 'off', strict: false, allowNetwork };
127
+ }
128
+ if (lower === 'read-only' || lower === 'readonly' || lower === 'ro') {
129
+ return { mode: 'read-only', strict: false, allowNetwork };
130
+ }
131
+ if (lower === 'read-only-strict') {
132
+ return { mode: 'read-only', strict: true, allowNetwork };
133
+ }
134
+ if (lower === 'strict') {
135
+ return { mode: 'workspace-write', strict: true, allowNetwork };
136
+ }
137
+ if (lower === 'workspace-write' || lower === 'on' || lower === '1' || lower === 'true' || lower === 'auto') {
138
+ return { mode: 'workspace-write', strict: false, allowNetwork };
139
+ }
140
+ return { mode: 'off', strict: false, allowNetwork };
141
+ }
142
+ function findExecutableInPath(binaryName, env = process.env) {
143
+ const pathVal = env.PATH || '';
144
+ for (const dir of pathVal.split(path.delimiter)) {
145
+ if (!dir)
146
+ continue;
147
+ const candidate = path.join(dir, binaryName);
148
+ try {
149
+ fs.accessSync(candidate, fs.constants.X_OK);
150
+ if (fs.statSync(candidate).isFile())
151
+ return candidate;
152
+ }
153
+ catch {
154
+ continue;
155
+ }
156
+ }
157
+ return null;
158
+ }
159
+ /**
160
+ * Probes whether an OS-level kernel sandbox backend is installed and functional
161
+ * (not blocked by a nested container or restricted user namespace).
162
+ */
163
+ export function probeOsSandbox(options) {
164
+ const platform = options?.platform ?? process.platform;
165
+ if (!options?.bypassCache && cachedProbe && cachedProbe.platform === platform) {
166
+ return cachedProbe.result;
167
+ }
168
+ let result;
169
+ if (platform === 'darwin') {
170
+ if (!fs.existsSync(SEATBELT_BIN)) {
171
+ result = {
172
+ backend: 'none',
173
+ platform,
174
+ available: false,
175
+ binaryPath: null,
176
+ reason: 'macOS sandbox-exec binary not found.'
177
+ };
178
+ }
179
+ else {
180
+ const check = spawnSync(SEATBELT_BIN, ['-p', '(version 1)(allow default)', '/usr/bin/true'], {
181
+ stdio: 'ignore',
182
+ timeout: 3000
183
+ });
184
+ if (check.status === 0) {
185
+ result = {
186
+ backend: 'seatbelt',
187
+ platform,
188
+ available: true,
189
+ binaryPath: SEATBELT_BIN,
190
+ reason: 'macOS Seatbelt (sandbox-exec) active and verified.'
191
+ };
192
+ }
193
+ else {
194
+ result = {
195
+ backend: 'none',
196
+ platform,
197
+ available: false,
198
+ binaryPath: SEATBELT_BIN,
199
+ reason: 'macOS Seatbelt cannot apply in this environment (likely nested sandbox).'
200
+ };
201
+ }
202
+ }
203
+ }
204
+ else if (platform === 'linux') {
205
+ const bwrapPath = findExecutableInPath('bwrap');
206
+ if (!bwrapPath) {
207
+ result = {
208
+ backend: 'none',
209
+ platform,
210
+ available: false,
211
+ binaryPath: null,
212
+ reason: 'Linux bubblewrap (bwrap) is not installed.'
213
+ };
214
+ }
215
+ else {
216
+ const check = spawnSync(bwrapPath, ['--ro-bind', '/', '/', '--dev', '/dev', '--proc', '/proc', '/bin/true'], {
217
+ stdio: 'ignore',
218
+ timeout: 3000
219
+ });
220
+ if (check.status === 0) {
221
+ result = {
222
+ backend: 'bubblewrap',
223
+ platform,
224
+ available: true,
225
+ binaryPath: bwrapPath,
226
+ reason: 'Linux bubblewrap (bwrap) namespaces active and verified.'
227
+ };
228
+ }
229
+ else {
230
+ result = {
231
+ backend: 'none',
232
+ platform,
233
+ available: false,
234
+ binaryPath: bwrapPath,
235
+ reason: 'Linux bubblewrap (bwrap) unavailable (user namespaces disabled in container).'
236
+ };
237
+ }
238
+ }
239
+ }
240
+ else {
241
+ result = {
242
+ backend: 'none',
243
+ platform,
244
+ available: false,
245
+ binaryPath: null,
246
+ reason: `Kernel subprocess sandboxing is not implemented for platform "${platform}"; application sandbox and env isolation remain active.`
247
+ };
248
+ }
249
+ if (!options?.bypassCache) {
250
+ cachedProbe = { platform, result };
251
+ }
252
+ return result;
253
+ }
254
+ /**
255
+ * Generates an Apple Seatbelt SBPL profile for macOS `sandbox-exec`.
256
+ * Uses Seatbelt's last-match-wins semantics:
257
+ * 1. Allow default reads/exec of system libraries & toolchains.
258
+ * 2. Optionally deny remote outbound IP connections (`allowNetwork === false`).
259
+ * 3. Deny all `file-write*`, then allow only safe device nodes, workspace roots,
260
+ * temp dirs, and standard dev caches (in `workspace-write` mode).
261
+ * 4. Explicitly deny `file-write*` on shell startup profiles and credential vaults.
262
+ * 5. Explicitly deny `file-read*` on credential vaults (unless the user explicitly
263
+ * selected that directory as their workspace).
264
+ */
265
+ export function buildSeatbeltProfile(options) {
266
+ const mode = options.mode ?? 'workspace-write';
267
+ const homeDir = options.homeDir ?? os.homedir();
268
+ const tmpDir = options.tmpDir ?? os.tmpdir();
269
+ const workspaces = options.workspaceRoots && options.workspaceRoots.length > 0
270
+ ? [...options.workspaceRoots, options.cwd]
271
+ : [options.cwd];
272
+ const lines = [
273
+ '(version 1)',
274
+ '(allow default)'
275
+ ];
276
+ if (options.allowNetwork === false) {
277
+ lines.push('(deny network-outbound (remote ip))');
278
+ }
279
+ lines.push('(deny file-write*)');
280
+ // Always allow writing to standard harmless device sinks
281
+ const safeDeviceLiterals = [
282
+ '/dev/null',
283
+ '/dev/zero',
284
+ '/dev/tty',
285
+ '/dev/ptmx',
286
+ '/dev/dtracehelper',
287
+ '/dev/stdout',
288
+ '/dev/stderr'
289
+ ];
290
+ lines.push(`(allow file-write* ${safeDeviceLiterals.map(p => `(literal "${p}")`).join(' ')})`);
291
+ if (mode === 'workspace-write') {
292
+ const writableSubpaths = new Set();
293
+ const addWritable = (rawPath) => {
294
+ for (const variant of resolveCanonicalPaths(rawPath)) {
295
+ const escaped = escapeSeatbeltPath(variant);
296
+ if (escaped)
297
+ writableSubpaths.add(escaped);
298
+ }
299
+ };
300
+ for (const ws of workspaces) {
301
+ addWritable(ws);
302
+ }
303
+ if (options.includeTempDirs !== false) {
304
+ for (const t of ['/tmp', '/private/tmp', '/private/var/tmp', '/private/var/folders', tmpDir]) {
305
+ if (t)
306
+ addWritable(t);
307
+ }
308
+ }
309
+ if (options.allowDevCaches !== false && homeDir) {
310
+ for (const rel of DEV_CACHE_SUBPATHS) {
311
+ addWritable(path.join(homeDir, rel));
312
+ }
313
+ }
314
+ if (writableSubpaths.size > 0) {
315
+ const clauses = [...writableSubpaths].map(p => `(subpath "${p}")`).join(' ');
316
+ lines.push(`(allow file-write* ${clauses})`);
317
+ }
318
+ }
319
+ // Last-match-wins: shell startup persistence targets remain strictly unwritable
320
+ if (homeDir) {
321
+ const denyWriteLiterals = new Set();
322
+ for (const rel of SHELL_PERSISTENCE_FILES) {
323
+ const full = path.join(homeDir, rel);
324
+ for (const variant of resolveCanonicalPaths(full)) {
325
+ const escaped = escapeSeatbeltPath(variant);
326
+ if (escaped)
327
+ denyWriteLiterals.add(escaped);
328
+ }
329
+ }
330
+ if (denyWriteLiterals.size > 0) {
331
+ lines.push(`(deny file-write* ${[...denyWriteLiterals].map(p => `(literal "${p}")`).join(' ')})`);
332
+ }
333
+ }
334
+ // Last-match-wins: credential vaults denied for both read and write unless explicitly chosen as workspace
335
+ const denyCredSubpaths = new Set();
336
+ if (homeDir) {
337
+ for (const rel of CREDENTIAL_SUBPATHS) {
338
+ const full = path.join(homeDir, rel);
339
+ if (workspaceOverlapsPath(workspaces, full))
340
+ continue;
341
+ for (const variant of resolveCanonicalPaths(full)) {
342
+ const escaped = escapeSeatbeltPath(variant);
343
+ if (escaped)
344
+ denyCredSubpaths.add(escaped);
345
+ }
346
+ }
347
+ }
348
+ if (Array.isArray(options.extraDenyReadPaths)) {
349
+ for (const extra of options.extraDenyReadPaths) {
350
+ for (const variant of resolveCanonicalPaths(extra)) {
351
+ const escaped = escapeSeatbeltPath(variant);
352
+ if (escaped)
353
+ denyCredSubpaths.add(escaped);
354
+ }
355
+ }
356
+ }
357
+ if (denyCredSubpaths.size > 0) {
358
+ const clauses = [...denyCredSubpaths].map(p => `(subpath "${p}")`).join(' ');
359
+ lines.push(`(deny file-read* ${clauses})`);
360
+ lines.push(`(deny file-write* ${clauses})`);
361
+ }
362
+ return `${lines.join('\n')}\n`;
363
+ }
364
+ /**
365
+ * Generates shell-free argv for Linux `bwrap` (bubblewrap) isolation.
366
+ */
367
+ export function buildBubblewrapArgs(shell, shellArgs, options) {
368
+ const mode = options.mode ?? 'workspace-write';
369
+ const homeDir = options.homeDir ?? os.homedir();
370
+ const workspaces = options.workspaceRoots && options.workspaceRoots.length > 0
371
+ ? [...options.workspaceRoots, options.cwd]
372
+ : [options.cwd];
373
+ const args = [
374
+ '--die-with-parent',
375
+ '--ro-bind', '/', '/',
376
+ '--dev', '/dev',
377
+ '--proc', '/proc'
378
+ ];
379
+ if (options.includeTempDirs !== false) {
380
+ args.push('--tmpfs', '/tmp');
381
+ }
382
+ if (options.allowNetwork === false) {
383
+ args.push('--unshare-net');
384
+ }
385
+ if (mode === 'workspace-write') {
386
+ const bound = new Set();
387
+ const bindIfExists = (rawPath) => {
388
+ const resolved = path.resolve(rawPath);
389
+ if (bound.has(resolved))
390
+ return;
391
+ if (!fs.existsSync(resolved))
392
+ return;
393
+ bound.add(resolved);
394
+ args.push('--bind', resolved, resolved);
395
+ };
396
+ for (const ws of workspaces) {
397
+ bindIfExists(ws);
398
+ }
399
+ if (options.allowDevCaches !== false && homeDir) {
400
+ for (const rel of DEV_CACHE_SUBPATHS) {
401
+ bindIfExists(path.join(homeDir, rel));
402
+ }
403
+ }
404
+ }
405
+ // Mask existing credential directories with empty tmpfs mounts unless inside selected workspace
406
+ if (homeDir) {
407
+ for (const rel of ['.ssh', '.aws', '.gnupg', '.kube', '.causyne']) {
408
+ const full = path.join(homeDir, rel);
409
+ if (workspaceOverlapsPath(workspaces, full))
410
+ continue;
411
+ try {
412
+ if (fs.existsSync(full) && fs.statSync(full).isDirectory()) {
413
+ args.push('--tmpfs', full);
414
+ }
415
+ }
416
+ catch {
417
+ continue;
418
+ }
419
+ }
420
+ }
421
+ args.push('--chdir', path.resolve(options.cwd), '--', shell, ...shellArgs);
422
+ return args;
423
+ }
424
+ /**
425
+ * Wraps a `(shell, shellArgs)` invocation in an OS kernel sandbox when enabled.
426
+ */
427
+ export function wrapCommandWithOsSandbox(shell, shellArgs, options) {
428
+ const mode = options.mode ?? 'off';
429
+ if (mode === 'off') {
430
+ return {
431
+ command: shell,
432
+ args: [...shellArgs],
433
+ sandboxed: false,
434
+ backend: 'none',
435
+ mode: 'off'
436
+ };
437
+ }
438
+ const platform = options.platform ?? process.platform;
439
+ const backend = options.backendOverride
440
+ ?? (probeOsSandbox({ platform }).available ? probeOsSandbox({ platform }).backend : 'none');
441
+ if (backend === 'seatbelt') {
442
+ const profile = buildSeatbeltProfile({ ...options, mode });
443
+ return {
444
+ command: options.binaryPathOverride || SEATBELT_BIN,
445
+ args: ['-p', profile, '--', shell, ...shellArgs],
446
+ sandboxed: true,
447
+ backend: 'seatbelt',
448
+ mode,
449
+ profile
450
+ };
451
+ }
452
+ if (backend === 'bubblewrap') {
453
+ const bin = options.binaryPathOverride || probeOsSandbox({ platform }).binaryPath || 'bwrap';
454
+ return {
455
+ command: bin,
456
+ args: buildBubblewrapArgs(shell, shellArgs, { ...options, mode }),
457
+ sandboxed: true,
458
+ backend: 'bubblewrap',
459
+ mode
460
+ };
461
+ }
462
+ if (options.strict) {
463
+ const probe = probeOsSandbox({ platform });
464
+ throw new Error(`Strict OS sandbox requested (${mode}) but no kernel sandbox backend is available: ${probe.reason}`);
465
+ }
466
+ return {
467
+ command: shell,
468
+ args: [...shellArgs],
469
+ sandboxed: false,
470
+ backend: 'none',
471
+ mode
472
+ };
473
+ }