@theokit/sdk 5.12.0 → 5.13.0

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 (139) hide show
  1. package/CHANGELOG.md +68 -0
  2. package/dist/{agent-IG7BP6GN.js → agent-5DSDDH7K.js} +5 -5
  3. package/dist/{agent-IG7BP6GN.js.map → agent-5DSDDH7K.js.map} +1 -1
  4. package/dist/{agent-CVzDy_Oj.d.ts → agent-DSMuwADp.d.ts} +9 -2
  5. package/dist/{agent-BVKIUP7F.cjs → agent-WOMRT3KX.cjs} +6 -6
  6. package/dist/{agent-BVKIUP7F.cjs.map → agent-WOMRT3KX.cjs.map} +1 -1
  7. package/dist/{agent-Cn0sphpA.d.cts → agent-iW5kPpfT.d.cts} +9 -2
  8. package/dist/{chunk-XJ4C4NFX.js → chunk-2PRGRYEQ.js} +61 -47
  9. package/dist/chunk-2PRGRYEQ.js.map +1 -0
  10. package/dist/{chunk-HN4IKB6X.cjs → chunk-2XWAYCFM.cjs} +15 -13
  11. package/dist/chunk-2XWAYCFM.cjs.map +1 -0
  12. package/dist/{chunk-VVGFZQZC.js → chunk-3LMVJTNJ.js} +9 -5
  13. package/dist/chunk-3LMVJTNJ.js.map +1 -0
  14. package/dist/{chunk-IO4RI5ZJ.cjs → chunk-47EACDOC.cjs} +4 -4
  15. package/dist/{chunk-IO4RI5ZJ.cjs.map → chunk-47EACDOC.cjs.map} +1 -1
  16. package/dist/{chunk-LSWHDOCL.cjs → chunk-4UYHP6NF.cjs} +64 -48
  17. package/dist/chunk-4UYHP6NF.cjs.map +1 -0
  18. package/dist/{chunk-ZLFFDPXC.js → chunk-73IITAF7.js} +36 -14
  19. package/dist/chunk-73IITAF7.js.map +1 -0
  20. package/dist/{chunk-XRPMZ7TO.js → chunk-CYWOJA6B.js} +6 -4
  21. package/dist/chunk-CYWOJA6B.js.map +1 -0
  22. package/dist/{chunk-AQW54OWQ.js → chunk-DFBWYETS.js} +5 -3
  23. package/dist/chunk-DFBWYETS.js.map +1 -0
  24. package/dist/{chunk-YOVZMN4P.cjs → chunk-DVP3YMDA.cjs} +3 -3
  25. package/dist/{chunk-YOVZMN4P.cjs.map → chunk-DVP3YMDA.cjs.map} +1 -1
  26. package/dist/{chunk-BRWI4HLK.cjs → chunk-FLDHYF5C.cjs} +13 -3
  27. package/dist/chunk-FLDHYF5C.cjs.map +1 -0
  28. package/dist/{chunk-BJ7BPLQK.js → chunk-JX4LB6XO.js} +124 -13
  29. package/dist/chunk-JX4LB6XO.js.map +1 -0
  30. package/dist/{chunk-Q6WT5535.cjs → chunk-KL7ZUMK3.cjs} +161 -50
  31. package/dist/chunk-KL7ZUMK3.cjs.map +1 -0
  32. package/dist/{chunk-FEAWEBWN.cjs → chunk-PDOXYXWX.cjs} +6 -4
  33. package/dist/chunk-PDOXYXWX.cjs.map +1 -0
  34. package/dist/{chunk-EEK7S77K.js → chunk-QGDPMM3C.js} +13 -3
  35. package/dist/chunk-QGDPMM3C.js.map +1 -0
  36. package/dist/{chunk-ZWLFHSON.cjs → chunk-R35ZJAYT.cjs} +38 -15
  37. package/dist/chunk-R35ZJAYT.cjs.map +1 -0
  38. package/dist/{chunk-4YD2WI57.cjs → chunk-R427EOZE.cjs} +19 -15
  39. package/dist/chunk-R427EOZE.cjs.map +1 -0
  40. package/dist/{chunk-TLVI2OQK.cjs → chunk-SETHRLQS.cjs} +18 -2
  41. package/dist/chunk-SETHRLQS.cjs.map +1 -0
  42. package/dist/{chunk-BO3PV3OP.js → chunk-TDED5XES.js} +18 -3
  43. package/dist/chunk-TDED5XES.js.map +1 -0
  44. package/dist/{chunk-4GUFNDZR.js → chunk-XOYNB3YN.js} +3 -3
  45. package/dist/{chunk-4GUFNDZR.js.map → chunk-XOYNB3YN.js.map} +1 -1
  46. package/dist/{chunk-NJBJ3CUG.js → chunk-ZTP6ZACR.js} +3 -3
  47. package/dist/{chunk-NJBJ3CUG.js.map → chunk-ZTP6ZACR.js.map} +1 -1
  48. package/dist/{compact-session-3U2JYTVG.js → compact-session-5HMX6KYT.js} +3 -3
  49. package/dist/{compact-session-3U2JYTVG.js.map → compact-session-5HMX6KYT.js.map} +1 -1
  50. package/dist/{compact-session-NM56BREJ.cjs → compact-session-B7P6EU3Z.cjs} +12 -12
  51. package/dist/{compact-session-NM56BREJ.cjs.map → compact-session-B7P6EU3Z.cjs.map} +1 -1
  52. package/dist/{cron-BWDYetbq.d.cts → cron-BvxrLW5J.d.cts} +1 -1
  53. package/dist/{cron-CHn-F0fC.d.ts → cron-DdKzwJqK.d.ts} +1 -1
  54. package/dist/cron.cjs +5 -5
  55. package/dist/cron.d.cts +2 -2
  56. package/dist/cron.d.ts +2 -2
  57. package/dist/cron.js +4 -4
  58. package/dist/eval.cjs +9 -9
  59. package/dist/eval.js +4 -4
  60. package/dist/{executor-HKHT4CWS.cjs → executor-5QL5AXIZ.cjs} +18 -15
  61. package/dist/executor-5QL5AXIZ.cjs.map +1 -0
  62. package/dist/{executor-3D2UDJHW.js → executor-THUXNAFR.js} +6 -3
  63. package/dist/executor-THUXNAFR.js.map +1 -0
  64. package/dist/generate-object-A5F576IT.cjs +20 -0
  65. package/dist/{generate-object-XBWD2PU7.cjs.map → generate-object-A5F576IT.cjs.map} +1 -1
  66. package/dist/{generate-object-S7MNVF2V.js → generate-object-TBDOBBYW.js} +4 -4
  67. package/dist/{generate-object-S7MNVF2V.js.map → generate-object-TBDOBBYW.js.map} +1 -1
  68. package/dist/generate-object.d.ts +14 -1
  69. package/dist/index.cjs +43 -43
  70. package/dist/index.d.cts +30 -4
  71. package/dist/index.d.ts +30 -4
  72. package/dist/index.js +13 -13
  73. package/dist/{inject-session-THABTKJY.js → inject-session-75L3NCNL.js} +3 -3
  74. package/dist/{inject-session-THABTKJY.js.map → inject-session-75L3NCNL.js.map} +1 -1
  75. package/dist/{inject-session-JVTZNQF6.cjs → inject-session-WOH7TPDX.cjs} +4 -4
  76. package/dist/{inject-session-JVTZNQF6.cjs.map → inject-session-WOH7TPDX.cjs.map} +1 -1
  77. package/dist/internal/providers/discovery.d.ts +2 -2
  78. package/dist/internal/providers/trust-gate.d.ts +35 -0
  79. package/dist/internal/runtime/plugin-loader/manifest-entry-import.d.ts +17 -0
  80. package/dist/internal/runtime/plugin-loader/workspace-plugin-trust.d.ts +16 -0
  81. package/dist/internal/structured-output-helpers.d.ts +5 -2
  82. package/dist/sandbox/bwrap.d.cts +10 -8
  83. package/dist/sandbox/bwrap.d.ts +10 -8
  84. package/dist/sandbox/deny-read.d.cts +24 -0
  85. package/dist/sandbox/deny-read.d.ts +24 -0
  86. package/dist/sandbox/index.cjs +198 -46
  87. package/dist/sandbox/index.cjs.map +1 -1
  88. package/dist/sandbox/index.d.cts +2 -1
  89. package/dist/sandbox/index.d.ts +2 -1
  90. package/dist/sandbox/index.js +184 -36
  91. package/dist/sandbox/index.js.map +1 -1
  92. package/dist/sandbox/linux-sandbox.d.cts +40 -5
  93. package/dist/sandbox/linux-sandbox.d.ts +40 -5
  94. package/dist/sandbox/local-sandbox.d.cts +3 -1
  95. package/dist/sandbox/local-sandbox.d.ts +3 -1
  96. package/dist/sandbox/seccomp-delivery.d.cts +49 -0
  97. package/dist/sandbox/seccomp-delivery.d.ts +49 -0
  98. package/dist/sandbox/shell-escape.d.cts +14 -2
  99. package/dist/sandbox/shell-escape.d.ts +14 -2
  100. package/dist/sandbox/types.d.cts +45 -0
  101. package/dist/sandbox/types.d.ts +45 -0
  102. package/dist/stream-object-AS4YYM4B.cjs +20 -0
  103. package/dist/{stream-object-TEEK3CAX.cjs.map → stream-object-AS4YYM4B.cjs.map} +1 -1
  104. package/dist/stream-object-EKM4WGTI.js +7 -0
  105. package/dist/{stream-object-R6SMYV4R.js.map → stream-object-EKM4WGTI.js.map} +1 -1
  106. package/dist/stream-object.d.ts +14 -1
  107. package/dist/subagents-loader.d.cts +1 -1
  108. package/dist/subagents-loader.d.ts +1 -1
  109. package/dist/types/agent.d.ts +8 -1
  110. package/dist/workflow-as-tool.d.ts +39 -5
  111. package/dist/workflow-errors.d.ts +16 -0
  112. package/dist/workflow.cjs +31 -23
  113. package/dist/workflow.d.cts +54 -4
  114. package/dist/workflow.d.ts +54 -4
  115. package/dist/workflow.js +2 -2
  116. package/docs/error-codes.md +16 -13
  117. package/docs/harness-capability-map.md +51 -5
  118. package/package.json +1 -1
  119. package/dist/chunk-4YD2WI57.cjs.map +0 -1
  120. package/dist/chunk-AQW54OWQ.js.map +0 -1
  121. package/dist/chunk-BJ7BPLQK.js.map +0 -1
  122. package/dist/chunk-BO3PV3OP.js.map +0 -1
  123. package/dist/chunk-BRWI4HLK.cjs.map +0 -1
  124. package/dist/chunk-EEK7S77K.js.map +0 -1
  125. package/dist/chunk-FEAWEBWN.cjs.map +0 -1
  126. package/dist/chunk-HN4IKB6X.cjs.map +0 -1
  127. package/dist/chunk-LSWHDOCL.cjs.map +0 -1
  128. package/dist/chunk-Q6WT5535.cjs.map +0 -1
  129. package/dist/chunk-TLVI2OQK.cjs.map +0 -1
  130. package/dist/chunk-VVGFZQZC.js.map +0 -1
  131. package/dist/chunk-XJ4C4NFX.js.map +0 -1
  132. package/dist/chunk-XRPMZ7TO.js.map +0 -1
  133. package/dist/chunk-ZLFFDPXC.js.map +0 -1
  134. package/dist/chunk-ZWLFHSON.cjs.map +0 -1
  135. package/dist/executor-3D2UDJHW.js.map +0 -1
  136. package/dist/executor-HKHT4CWS.cjs.map +0 -1
  137. package/dist/generate-object-XBWD2PU7.cjs +0 -20
  138. package/dist/stream-object-R6SMYV4R.js +0 -7
  139. package/dist/stream-object-TEEK3CAX.cjs +0 -20
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkBRWI4HLK_cjs = require('../chunk-BRWI4HLK.cjs');
3
+ var chunkFLDHYF5C_cjs = require('../chunk-FLDHYF5C.cjs');
4
4
  require('../chunk-2ZPEDVLM.cjs');
5
5
  var chunkCEGU5AVD_cjs = require('../chunk-CEGU5AVD.cjs');
6
6
  var chunkRNXXYF22_cjs = require('../chunk-RNXXYF22.cjs');
@@ -13,6 +13,64 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
13
13
 
14
14
  var path__default = /*#__PURE__*/_interopDefault(path);
15
15
 
16
+ var KEPT_ROOTS_ALWAYS = ["/tmp"];
17
+ function isSameOrInside(outer, inner) {
18
+ const rel = path__default.default.relative(outer, inner);
19
+ return rel === "" || !rel.startsWith("..") && !path__default.default.isAbsolute(rel);
20
+ }
21
+ function resolveEntry(entry) {
22
+ if (!path__default.default.isAbsolute(entry)) {
23
+ throw new TypeError(`denyReadPaths: "${entry}" is not an absolute path`);
24
+ }
25
+ try {
26
+ return fs.realpathSync(entry);
27
+ } catch (cause) {
28
+ throw new TypeError(`denyReadPaths: "${entry}" cannot be resolved: ${String(cause)}`);
29
+ }
30
+ }
31
+ function keptRoots(cwd) {
32
+ let real = cwd;
33
+ try {
34
+ real = fs.realpathSync(cwd);
35
+ } catch {
36
+ }
37
+ return [.../* @__PURE__ */ new Set([cwd, real, ...KEPT_ROOTS_ALWAYS])];
38
+ }
39
+ function denyReadFlags(paths, policy) {
40
+ if (paths === void 0 || paths.length === 0) return [];
41
+ if (policy.mode === "danger-full-access") {
42
+ throw new TypeError(
43
+ "denyReadPaths cannot be honoured under danger-full-access: no sandbox is applied"
44
+ );
45
+ }
46
+ const roots = keptRoots(policy.cwd);
47
+ const resolved = /* @__PURE__ */ new Set();
48
+ for (const entry of paths) {
49
+ const target = resolveEntry(entry);
50
+ const covered = roots.find((root) => isSameOrInside(target, root));
51
+ if (covered !== void 0) {
52
+ throw new TypeError(
53
+ `denyReadPaths: "${entry}" would hide "${covered}", which the command needs`
54
+ );
55
+ }
56
+ resolved.add(target);
57
+ }
58
+ return [...resolved].flatMap(
59
+ (target) => fs.statSync(target).isDirectory() ? ["--tmpfs", target] : ["--ro-bind", "/dev/null", target]
60
+ );
61
+ }
62
+ function refuseUnhonourableDenyRead(paths, mode, detect) {
63
+ if (paths === void 0 || paths.length === 0) return;
64
+ if (mode === "danger-full-access") denyReadFlags(paths, { mode, cwd: "/" });
65
+ const detection = detect();
66
+ if (!detection.ok) {
67
+ throw new chunkFLDHYF5C_cjs.SandboxNotAvailableError(
68
+ `denyReadPaths needs kernel confinement and it is unavailable (${detection.reason}); refusing to run unconfined`
69
+ );
70
+ }
71
+ }
72
+
73
+ // src/sandbox/bwrap.ts
16
74
  function pushWorkspaceBinds(argv, cwd, hasGit, gitDir) {
17
75
  for (const root of workspaceWriteRoots(cwd)) argv.push("--bind", root, root);
18
76
  if (hasGit) argv.push("--ro-bind", gitDir, gitDir);
@@ -31,8 +89,9 @@ function writableRootsFor(mode, cwd) {
31
89
  }
32
90
  }
33
91
  function buildBwrapArgv(mode, opts) {
34
- if (mode === "danger-full-access") return null;
35
92
  const cwd = path__default.default.resolve(opts.cwd);
93
+ const denyFlags = denyReadFlags(opts.denyReadPaths, { mode, cwd });
94
+ if (mode === "danger-full-access") return null;
36
95
  const gitDir = path__default.default.join(cwd, ".git");
37
96
  const hasGit = opts.gitDirExists ?? fs.existsSync(gitDir);
38
97
  const argv = [
@@ -59,6 +118,7 @@ function buildBwrapArgv(mode, opts) {
59
118
  };
60
119
  for (const [k, v] of Object.entries(setenv)) argv.push("--setenv", k, v);
61
120
  if (mode === "workspace-write") pushWorkspaceBinds(argv, cwd, hasGit, gitDir);
121
+ argv.push(...denyFlags);
62
122
  argv.push("--chdir", cwd, "--");
63
123
  return argv;
64
124
  }
@@ -185,7 +245,7 @@ function buildSeccompFilter(opts) {
185
245
  const denyIdx = body.length - 1;
186
246
  push(RET_K, SECCOMP_RET_KILL_PROCESS);
187
247
  const killIdx = body.length - 1;
188
- const resolve = (i, t) => {
248
+ const resolve2 = (i, t) => {
189
249
  const abs = t === ALLOW ? allowIdx : t === DENY ? denyIdx : t === KILL ? killIdx : i + 1 + t;
190
250
  const off = abs - (i + 1);
191
251
  if (off < 0 || off > 255) throw new RangeError(`seccomp jump out of range at ${i}: ${off}`);
@@ -193,7 +253,7 @@ function buildSeccompFilter(opts) {
193
253
  };
194
254
  for (const [i, b] of body.entries()) {
195
255
  if (b.code === JEQ_K || b.code === JGE_K) {
196
- insns.push(jmp(b.code, b.k, resolve(i, b.jt), resolve(i, b.jf)));
256
+ insns.push(jmp(b.code, b.k, resolve2(i, b.jt), resolve2(i, b.jf)));
197
257
  } else {
198
258
  insns.push(stmt(b.code, b.k));
199
259
  }
@@ -207,15 +267,90 @@ function buildSeccompFilter(opts) {
207
267
  });
208
268
  return buf;
209
269
  }
270
+ function nonX64SeccompWarning(arch) {
271
+ return `[sandbox] seccomp syscall filter unsupported on ${arch} (x86_64 only in v1) \u2014 running without the filter; bwrap FS/network confinement still applies.`;
272
+ }
273
+ var warnedNonX64Program = false;
274
+ function seccompProgramForArch(arch, warn) {
275
+ if (arch !== "x64") {
276
+ if (!warnedNonX64Program) {
277
+ warnedNonX64Program = true;
278
+ warn(nonX64SeccompWarning(arch));
279
+ }
280
+ return void 0;
281
+ }
282
+ return buildSeccompFilter({ networkRestricted: true });
283
+ }
284
+ var memoizedProgram;
285
+ function restrictedSeccompProgram(warn) {
286
+ if (memoizedProgram === void 0)
287
+ memoizedProgram = seccompProgramForArch(process.arch, warn) ?? null;
288
+ return memoizedProgram ?? void 0;
289
+ }
290
+ function octalPrintfArg(program) {
291
+ let out = "";
292
+ for (const byte of program) out += `\\${byte.toString(8).padStart(3, "0")}`;
293
+ return out;
294
+ }
295
+ function assertSeccompProgramShape(program) {
296
+ if (program.length === 0 || program.length % 8 !== 0) {
297
+ throw new TypeError(
298
+ `seccompProgram must be a positive multiple of 8 bytes, got ${program.length}`
299
+ );
300
+ }
301
+ }
302
+ var PIPE_SCRIPT = '{ p=$1; shift; printf "$p" | exec "$@" 3<&0 0<&4 4<&-; } 4<&0';
303
+ function wrapWithSeccompProgram(bwrapArgv, command, program) {
304
+ assertSeccompProgramShape(program);
305
+ const words = [octalPrintfArg(program), ...bwrapArgv, "--seccomp", "3", "--", "/bin/sh", "-c"];
306
+ return `exec /bin/sh -c ${chunkFLDHYF5C_cjs.shellEscapePosix(PIPE_SCRIPT)} sh ${[...words, command].map(chunkFLDHYF5C_cjs.shellEscapePosix).join(" ")}`;
307
+ }
308
+ var programsWritten = /* @__PURE__ */ new Map();
309
+ function rememberSeccompFile(path3, program) {
310
+ programsWritten.set(path.resolve(path3), Buffer.from(program));
311
+ }
312
+ function removeDirOnExit(dir) {
313
+ const cleanup = () => fs.rmSync(dir, { recursive: true, force: true });
314
+ process.once("exit", cleanup);
315
+ for (const signal of ["SIGINT", "SIGTERM"]) {
316
+ process.prependOnceListener(signal, () => {
317
+ cleanup();
318
+ if (process.listenerCount(signal) === 0) process.kill(process.pid, signal);
319
+ });
320
+ }
321
+ }
322
+ function wrapWithSeccompPath(bwrapArgv, policy, command, seccompPath) {
323
+ const program = programsWritten.get(path.resolve(seccompPath));
324
+ const bind = program === void 0 ? "--ro-bind" : "--ro-bind-try";
325
+ const flags = [
326
+ ...bwrapArgv.slice(0, -3),
327
+ ...readOnlyBindForSeccompPath(policy.mode, policy.cwd, seccompPath, bind),
328
+ ...bwrapArgv.slice(-3, -1)
329
+ ];
330
+ if (program !== void 0) return wrapWithSeccompProgram(flags, command, program);
331
+ return `${[...flags, "--seccomp", "3", "--"].map(chunkFLDHYF5C_cjs.shellEscapePosix).join(" ")} /bin/sh -c ${chunkFLDHYF5C_cjs.shellEscapePosix(command)} 3< ${chunkFLDHYF5C_cjs.shellEscapePosix(seccompPath)}`;
332
+ }
333
+ function readOnlyBindForSeccompPath(mode, cwd, seccompPath, bind) {
334
+ const file = path.resolve(seccompPath);
335
+ const dir = path.dirname(file);
336
+ const roots = writableRootsFor(mode, path.resolve(cwd)) ?? [];
337
+ const covers = (root) => dir === "/" || root === dir || root.startsWith(`${dir}/`);
338
+ const target = roots.some(covers) ? file : dir;
339
+ return [bind, target, target];
340
+ }
210
341
 
211
342
  // src/sandbox/linux-sandbox.ts
212
343
  function wrapCommandForSandbox(mode, opts, command) {
213
- const argv = buildBwrapArgv(mode, { cwd: opts.cwd, network: opts.network, env: opts.env });
344
+ const argv = buildBwrapArgv(mode, opts);
214
345
  if (argv === null) return null;
215
346
  const bin = opts.bin ?? "bwrap";
216
- const seccompArgv = opts.seccompPath !== void 0 ? ["--seccomp", "3"] : [];
217
- const base = `${chunkBRWI4HLK_cjs.shellEscapePosix(bin)} ${[...argv.slice(0, -1), ...seccompArgv, "--"].map(chunkBRWI4HLK_cjs.shellEscapePosix).join(" ")} /bin/sh -c ${chunkBRWI4HLK_cjs.shellEscapePosix(command)}`;
218
- return opts.seccompPath !== void 0 ? `${base} 3< ${chunkBRWI4HLK_cjs.shellEscapePosix(opts.seccompPath)}` : base;
347
+ if (opts.seccompProgram !== void 0) {
348
+ return wrapWithSeccompProgram([bin, ...argv.slice(0, -1)], command, opts.seccompProgram);
349
+ }
350
+ if (opts.seccompPath === void 0) {
351
+ return `${[bin, ...argv].map(chunkFLDHYF5C_cjs.shellEscapePosix).join(" ")} /bin/sh -c ${chunkFLDHYF5C_cjs.shellEscapePosix(command)}`;
352
+ }
353
+ return wrapWithSeccompPath([bin, ...argv], { mode, cwd: opts.cwd }, command, opts.seccompPath);
219
354
  }
220
355
  var ENV_ALLOWLIST = [
221
356
  "PATH",
@@ -236,23 +371,35 @@ function allowlistedEnv(source = process.env) {
236
371
  }
237
372
  return out;
238
373
  }
239
- var LinuxSandbox = class extends chunkBRWI4HLK_cjs.LocalSandbox {
374
+ var LinuxSandbox = class extends chunkFLDHYF5C_cjs.LocalSandbox {
240
375
  mode;
241
376
  network;
242
377
  cwd;
243
378
  bin;
244
379
  env;
245
- /** M63 — path to the cBPF seccomp program written host-side; passed to `bwrap --seccomp 3` via a
246
- * shell redirect. `undefined` when the network is unrestricted OR generation failed (honest fallback). */
247
- seccompPath;
380
+ /** B-600 — the cBPF seccomp program, piped to `bwrap --seccomp 3` from memory (never a file a
381
+ * confined command could replace). `undefined` when the network is unrestricted or the arch is not
382
+ * x86_64 (honest fallback). */
383
+ seccompProgram;
384
+ denyReadPaths;
385
+ /**
386
+ * `"none"` exactly when the wrap passes `--unshare-net` (see `buildBwrapArgv`): a confined mode and
387
+ * `network` not set. With `network: true`, or under `danger-full-access` where nothing is wrapped,
388
+ * the command reaches whatever the host does.
389
+ */
390
+ networkPolicy;
391
+ /** `denyReadPaths`: see `BwrapArgvOptions`; a list that cannot be honoured throws `TypeError` here. */
248
392
  constructor(config, opts) {
249
393
  super(config);
250
394
  this.mode = opts.mode;
251
395
  this.network = opts.network ?? false;
396
+ this.networkPolicy = this.network || this.mode === "danger-full-access" ? { mode: "unrestricted" } : { mode: "none" };
252
397
  this.cwd = config.workDir ?? process.cwd();
253
398
  this.bin = opts.bin ?? "bwrap";
254
399
  this.env = opts.env ?? allowlistedEnv();
255
- this.seccompPath = seccompPathForNetwork(this.network);
400
+ this.seccompProgram = seccompProgramForNetwork(this.network);
401
+ this.denyReadPaths = opts.denyReadPaths;
402
+ denyReadFlags(this.denyReadPaths, { mode: this.mode, cwd: this.cwd });
256
403
  }
257
404
  /** Extracted for test visibility — delegates to the pure `wrapCommandForSandbox` (M57, single wrap SoT). */
258
405
  wrapCommand(command) {
@@ -263,7 +410,8 @@ var LinuxSandbox = class extends chunkBRWI4HLK_cjs.LocalSandbox {
263
410
  network: this.network,
264
411
  env: this.env,
265
412
  bin: this.bin,
266
- seccompPath: this.seccompPath
413
+ seccompProgram: this.seccompProgram,
414
+ denyReadPaths: this.denyReadPaths
267
415
  },
268
416
  command
269
417
  );
@@ -281,12 +429,12 @@ var LinuxSandbox = class extends chunkBRWI4HLK_cjs.LocalSandbox {
281
429
  * policy as everything else — if bwrap denies the path, the write fails, as it should. The content
282
430
  * goes over stdin (not argv) because argv has a size limit and file content does not.
283
431
  */
284
- async uploadFile(path2, content) {
285
- if (this.mode === "danger-full-access") return super.uploadFile(path2, content);
286
- const target = path2.startsWith("/") ? path2 : `${this.cwd}/${path2}`;
432
+ async uploadFile(path3, content) {
433
+ if (this.mode === "danger-full-access") return super.uploadFile(path3, content);
434
+ const target = path3.startsWith("/") ? path3 : `${this.cwd}/${path3}`;
287
435
  const b64 = Buffer.from(content).toString("base64");
288
436
  const r = await this.execute(
289
- `mkdir -p ${chunkBRWI4HLK_cjs.shellEscapePosix(path.dirname(target))} && printf %s ${chunkBRWI4HLK_cjs.shellEscapePosix(b64)} | base64 -d > ${chunkBRWI4HLK_cjs.shellEscapePosix(target)}`
437
+ `mkdir -p ${chunkFLDHYF5C_cjs.shellEscapePosix(path.dirname(target))} && printf %s ${chunkFLDHYF5C_cjs.shellEscapePosix(b64)} | base64 -d > ${chunkFLDHYF5C_cjs.shellEscapePosix(target)}`
290
438
  );
291
439
  if (r.exitCode !== 0) {
292
440
  throw new Error(
@@ -305,21 +453,18 @@ function seccompPathForArch(arch, warn) {
305
453
  if (arch !== "x64") {
306
454
  if (!warnedNonX64) {
307
455
  warnedNonX64 = true;
308
- warn(
309
- `[sandbox] seccomp syscall filter unsupported on ${arch} (x86_64 only in v1) \u2014 running without the filter; bwrap FS/network confinement still applies.`
310
- );
456
+ warn(nonX64SeccompWarning(arch));
311
457
  }
312
458
  return void 0;
313
459
  }
314
460
  try {
315
461
  const dir = fs.mkdtempSync(path.join(os.tmpdir(), "ab-seccomp-"));
316
- const path2 = path.join(dir, "filter.bpf");
317
- fs.writeFileSync(path2, buildSeccompFilter({ networkRestricted: true }));
318
- const cleanup = () => fs.rmSync(dir, { recursive: true, force: true });
319
- process.once("exit", cleanup);
320
- process.once("SIGINT", cleanup);
321
- process.once("SIGTERM", cleanup);
322
- return path2;
462
+ const path3 = path.join(dir, "filter.bpf");
463
+ const program = buildSeccompFilter({ networkRestricted: true });
464
+ fs.writeFileSync(path3, program);
465
+ rememberSeccompFile(path3, program);
466
+ removeDirOnExit(dir);
467
+ return path3;
323
468
  } catch (err) {
324
469
  warn(
325
470
  `[sandbox] seccomp filter unavailable (${err instanceof Error ? err.message : String(err)}) \u2014 running without syscall filter (bwrap FS/network confinement still applies).`
@@ -330,9 +475,9 @@ function seccompPathForArch(arch, warn) {
330
475
  var seccompFilterPath;
331
476
  function restrictedSeccompPath() {
332
477
  if (seccompFilterPath !== void 0) return seccompFilterPath ?? void 0;
333
- const path2 = seccompPathForArch(process.arch, (m) => console.warn(chunkRNXXYF22_cjs.redactSecrets(m)));
334
- seccompFilterPath = path2 ?? null;
335
- return path2;
478
+ const path3 = seccompPathForArch(process.arch, (m) => console.warn(chunkRNXXYF22_cjs.redactSecrets(m)));
479
+ seccompFilterPath = path3 ?? null;
480
+ return path3;
336
481
  }
337
482
  var warnedUnavailable = false;
338
483
  function __resetSandboxWarnLatchForTests() {
@@ -350,7 +495,8 @@ function resolveSandboxPosture(opts) {
350
495
  }
351
496
  function createSandboxBackend(opts) {
352
497
  const config = { workDir: opts.workDir, timeoutMs: opts.timeoutMs };
353
- if (opts.mode === "danger-full-access") return new chunkBRWI4HLK_cjs.LocalSandbox(config);
498
+ refuseUnhonourableDenyRead(opts.denyReadPaths, opts.mode, opts.detect ?? detectBwrapMemoized);
499
+ if (opts.mode === "danger-full-access") return new chunkFLDHYF5C_cjs.LocalSandbox(config);
354
500
  const detection = (opts.detect ?? detectBwrapMemoized)();
355
501
  if (!detection.ok) {
356
502
  if (!warnedUnavailable) {
@@ -360,18 +506,19 @@ function createSandboxBackend(opts) {
360
506
  `[sandbox] OS-level enforcement unavailable (${detection.reason}) \u2014 falling back to tool-level gating only (sandbox_mode=${opts.mode}).`
361
507
  );
362
508
  }
363
- return new chunkBRWI4HLK_cjs.LocalSandbox(config);
509
+ return new chunkFLDHYF5C_cjs.LocalSandbox(config);
364
510
  }
365
- return new LinuxSandbox(config, { mode: opts.mode, network: opts.network, bin: detection.bin });
511
+ return new LinuxSandbox(config, { ...opts, bin: detection.bin });
366
512
  }
367
513
  var interactiveWarned = false;
368
514
  function __resetInteractiveWarnLatchForTests() {
369
515
  interactiveWarned = false;
370
516
  }
371
- function seccompPathForNetwork(networkOpen) {
372
- return networkOpen ? void 0 : restrictedSeccompPath();
517
+ function seccompProgramForNetwork(networkOpen) {
518
+ return networkOpen ? void 0 : restrictedSeccompProgram((m) => console.warn(chunkRNXXYF22_cjs.redactSecrets(m)));
373
519
  }
374
520
  function decideConfinement(opts) {
521
+ refuseUnhonourableDenyRead(opts.denyReadPaths, opts.mode, opts.detect ?? detectBwrapMemoized);
375
522
  if (opts.mode === "danger-full-access") return null;
376
523
  const detection = (opts.detect ?? detectBwrapMemoized)();
377
524
  if (detection.ok) return detection.bin;
@@ -395,7 +542,8 @@ function interactiveWrapCommand(opts) {
395
542
  network: opts.network ?? false,
396
543
  env: allowlistedEnv(),
397
544
  bin,
398
- seccompPath: seccompPathForNetwork(opts.network ?? false)
545
+ seccompProgram: seccompProgramForNetwork(opts.network ?? false),
546
+ denyReadPaths: opts.denyReadPaths
399
547
  },
400
548
  command
401
549
  );
@@ -417,7 +565,7 @@ var RepoProvisionError = class extends chunkCEGU5AVD_cjs.TheokitAgentError {
417
565
  };
418
566
  var SAFE_INSTANCE_ID = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
419
567
  async function provisionRepo(sandboxOrOpts, maybeOpts) {
420
- const sandbox = maybeOpts !== void 0 ? sandboxOrOpts : new chunkBRWI4HLK_cjs.LocalSandbox();
568
+ const sandbox = maybeOpts !== void 0 ? sandboxOrOpts : new chunkFLDHYF5C_cjs.LocalSandbox();
421
569
  const opts = maybeOpts ?? sandboxOrOpts;
422
570
  const { repoUrl, ref, instanceId } = opts;
423
571
  if (!SAFE_INSTANCE_ID.test(instanceId)) {
@@ -430,20 +578,20 @@ async function provisionRepo(sandboxOrOpts, maybeOpts) {
430
578
  throw new RepoProvisionError(instanceId, `invalid ref: must not begin with '-' (got ${ref})`);
431
579
  }
432
580
  const clone = await sandbox.execute(
433
- `git -c protocol.ext.allow=never clone --quiet -- ${chunkBRWI4HLK_cjs.shellEscapePosix(repoUrl)} ${chunkBRWI4HLK_cjs.shellEscapePosix(instanceId)}`
581
+ `git -c protocol.ext.allow=never clone --quiet -- ${chunkFLDHYF5C_cjs.shellEscapePosix(repoUrl)} ${chunkFLDHYF5C_cjs.shellEscapePosix(instanceId)}`
434
582
  );
435
583
  if (clone.exitCode !== 0) {
436
584
  throw new RepoProvisionError(instanceId, `clone failed: ${clone.stderr.trim()}`);
437
585
  }
438
586
  const top = await sandbox.execute(
439
- `git -C ${chunkBRWI4HLK_cjs.shellEscapePosix(instanceId)} rev-parse --show-toplevel`
587
+ `git -C ${chunkFLDHYF5C_cjs.shellEscapePosix(instanceId)} rev-parse --show-toplevel`
440
588
  );
441
589
  if (top.exitCode !== 0) {
442
590
  throw new RepoProvisionError(instanceId, `resolve repoDir failed: ${top.stderr.trim()}`);
443
591
  }
444
592
  const repoDir = top.stdout.trim();
445
593
  const checkout = await sandbox.execute(
446
- `git -C ${chunkBRWI4HLK_cjs.shellEscapePosix(repoDir)} checkout --quiet ${chunkBRWI4HLK_cjs.shellEscapePosix(ref)}`
594
+ `git -C ${chunkFLDHYF5C_cjs.shellEscapePosix(repoDir)} checkout --quiet ${chunkFLDHYF5C_cjs.shellEscapePosix(ref)}`
447
595
  );
448
596
  if (checkout.exitCode !== 0) {
449
597
  throw new RepoProvisionError(instanceId, `checkout ${ref} failed: ${checkout.stderr.trim()}`);
@@ -453,23 +601,27 @@ async function provisionRepo(sandboxOrOpts, maybeOpts) {
453
601
 
454
602
  Object.defineProperty(exports, "LocalSandbox", {
455
603
  enumerable: true,
456
- get: function () { return chunkBRWI4HLK_cjs.LocalSandbox; }
604
+ get: function () { return chunkFLDHYF5C_cjs.LocalSandbox; }
457
605
  });
458
606
  Object.defineProperty(exports, "SandboxBackend", {
459
607
  enumerable: true,
460
- get: function () { return chunkBRWI4HLK_cjs.SandboxBackend; }
608
+ get: function () { return chunkFLDHYF5C_cjs.SandboxBackend; }
461
609
  });
462
610
  Object.defineProperty(exports, "SandboxNotAvailableError", {
463
611
  enumerable: true,
464
- get: function () { return chunkBRWI4HLK_cjs.SandboxNotAvailableError; }
612
+ get: function () { return chunkFLDHYF5C_cjs.SandboxNotAvailableError; }
465
613
  });
466
614
  Object.defineProperty(exports, "SandboxSecurityError", {
467
615
  enumerable: true,
468
- get: function () { return chunkBRWI4HLK_cjs.SandboxSecurityError; }
616
+ get: function () { return chunkFLDHYF5C_cjs.SandboxSecurityError; }
469
617
  });
470
618
  Object.defineProperty(exports, "resolveSandbox", {
471
619
  enumerable: true,
472
- get: function () { return chunkBRWI4HLK_cjs.resolveSandbox; }
620
+ get: function () { return chunkFLDHYF5C_cjs.resolveSandbox; }
621
+ });
622
+ Object.defineProperty(exports, "shellEscapePosix", {
623
+ enumerable: true,
624
+ get: function () { return chunkFLDHYF5C_cjs.shellEscapePosix; }
473
625
  });
474
626
  exports.LinuxSandbox = LinuxSandbox;
475
627
  exports.RepoProvisionError = RepoProvisionError;