@agentswf/sandbox 0.2.0 → 0.3.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentswf/sandbox",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "agents.wf: the sandboxes a workflow opens, and their providers",
5
5
  "license": "MIT",
6
6
  "homepage": "https://agents.wf",
@@ -32,7 +32,7 @@
32
32
  "LICENSE"
33
33
  ],
34
34
  "dependencies": {
35
- "@agentswf/contract": "0.2.0"
35
+ "@agentswf/contract": "0.3.0"
36
36
  },
37
37
  "publishConfig": {
38
38
  "access": "public"
package/src/index.ts CHANGED
@@ -1,3 +1,10 @@
1
- export { DOORS_PREFIX, repositoryOf, resolveSandbox, withinReach } from "./resolve";
1
+ export {
2
+ checkSandboxSpec,
3
+ DOORS_PREFIX,
4
+ repositoryOf,
5
+ resolveRunBox,
6
+ resolveSandbox,
7
+ withinReach,
8
+ } from "./resolve";
2
9
  export * from "./seam";
3
10
  export { shellQuote } from "./secrets";
package/src/resolve.ts CHANGED
@@ -38,6 +38,11 @@ export type ResolveOptions = {
38
38
  providers: SandboxProviders;
39
39
  /** An agent's private spec, which may not carry `key` or `cwd`. */
40
40
  inline?: boolean;
41
+ /**
42
+ * awf's own folders in `machineRoot`: given, a path may lie in `machineRoot` outside them, as a
43
+ * whole run's box, which the operator writes, may reach another tool's folder there.
44
+ */
45
+ machineOwn?: readonly string[];
41
46
  /** The operator's home, for `~`. */
42
47
  home?: string;
43
48
  /** The operator's harness state, where its environment put it: no sandbox path may overlap it. */
@@ -56,23 +61,25 @@ export type ResolveOptions = {
56
61
  };
57
62
 
58
63
  /**
59
- * Checks an author's spec the way the types would, since a workflow is untyped at run time, and
60
- * resolves its paths once, at open: a sandbox holds what they named then, whatever moves later.
64
+ * Checks a spec's fields and their values, all but where its paths lead, and names its one
65
+ * provider, before anything is installed or opened: a run its caller boxes checks its specs this
66
+ * way, so a spec refused unboxed for its shape is refused boxed too. Its paths are checked against
67
+ * the machine when it is resolved.
61
68
  */
62
- export async function resolveSandbox(
69
+ export function checkSandboxSpec(
63
70
  spec: unknown,
64
- options: ResolveOptions,
65
- ): Promise<SandboxResolution> {
71
+ inline: boolean,
72
+ ): { spec: Record<string, unknown>; provider: SandboxEnvironmentKey } {
66
73
  if (!isRecord(spec)) throw new Error("a sandbox spec must be an object");
67
74
  const allowed = new Set<string>([
68
75
  ...REACH_KEYS,
69
76
  ...SANDBOX_ENVIRONMENTS,
70
- ...(options.inline ? [] : ["key", "cwd"]),
77
+ ...(inline ? [] : ["key", "cwd"]),
71
78
  ]);
72
79
  for (const key of Object.keys(spec)) {
73
80
  if (allowed.has(key)) continue;
74
81
  throw new Error(
75
- options.inline && (key === "key" || key === "cwd" || key === "provider")
82
+ inline && (key === "key" || key === "cwd" || key === "provider")
76
83
  ? `an agent's inline sandbox cannot name ${key}; open a sandbox and pass its ref to share one`
77
84
  : `unknown sandbox field ${JSON.stringify(key)}`,
78
85
  );
@@ -85,6 +92,28 @@ export async function resolveSandbox(
85
92
  if (provider === undefined) {
86
93
  throw new Error('a sandbox spec names its provider: add "srt": {} or "docker": {}');
87
94
  }
95
+ if (spec.cwd !== undefined) checkPath(spec.cwd, "cwd");
96
+ for (const field of ["read", "write", "sockets"] as const) {
97
+ for (const path of list(spec[field], field)) checkPath(path, field);
98
+ }
99
+ for (const domain of list(spec.network, "network")) {
100
+ if (!isDomain(domain)) throw new Error(`not a sandbox domain: ${JSON.stringify(domain)}`);
101
+ }
102
+ if (spec.webSearch !== undefined && typeof spec.webSearch !== "boolean") {
103
+ throw new Error("sandbox webSearch must be true or false");
104
+ }
105
+ return { spec, provider };
106
+ }
107
+
108
+ /**
109
+ * Checks an author's spec the way the types would, since a workflow is untyped at run time, and
110
+ * resolves its paths once, at open: a sandbox holds what they named then, whatever moves later.
111
+ */
112
+ export async function resolveSandbox(
113
+ given: unknown,
114
+ options: ResolveOptions,
115
+ ): Promise<SandboxResolution> {
116
+ const { spec, provider } = checkSandboxSpec(given, options.inline === true);
88
117
  const installed = options.providers.installed[provider];
89
118
  if (!installed) {
90
119
  const why = options.providers.unavailable?.[provider];
@@ -104,6 +133,10 @@ export async function resolveSandbox(
104
133
  ? undefined
105
134
  : await realpathMissing(options.coordinatorRoot);
106
135
  const harnessState = await Promise.all(options.harnessState.map(realpathMissing));
136
+ const machineOwn =
137
+ options.machineOwn === undefined
138
+ ? undefined
139
+ : await Promise.all(options.machineOwn.map(realpathMissing));
107
140
  const forbidden = (path: string, field: string) => {
108
141
  if (contains(path, home)) throw new Error(`sandbox ${field} ${path} would expose ~`);
109
142
  // A path within the run root would be another run's. One holding it is `hidden`.
@@ -117,8 +150,9 @@ export async function resolveSandbox(
117
150
  (root) => contains(path, root) || contains(root, path),
118
151
  );
119
152
  if (keys) throw new Error(`sandbox ${field} ${path} would expose keys in ${keys}`);
120
- if (contains(machine, path))
121
- throw new Error(`sandbox ${field} ${path} would expose ${machine}`);
153
+ const own = machineOwn?.find((root) => contains(root, path) || contains(path, root));
154
+ if (machineOwn ? contains(path, machine) || own : contains(machine, path))
155
+ throw new Error(`sandbox ${field} ${path} would expose ${own ?? machine}`);
122
156
  if (coordinatorRoot && (contains(path, coordinatorRoot) || contains(coordinatorRoot, path)))
123
157
  throw new Error(`sandbox ${field} ${path} would expose the coordinator sockets`);
124
158
  if (controlRoot && (contains(path, controlRoot) || insideDoors(controlRoot, path))) {
@@ -139,15 +173,7 @@ export async function resolveSandbox(
139
173
  const write = unique(await paths("write"));
140
174
  const read = unique(await paths("read")).filter((path) => !write.includes(path));
141
175
  const sockets = unique(await paths("sockets"));
142
- if (spec.webSearch !== undefined && typeof spec.webSearch !== "boolean") {
143
- throw new Error("sandbox webSearch must be true or false");
144
- }
145
- const network = unique(
146
- list(spec.network, "network").map((domain) => {
147
- if (!isDomain(domain)) throw new Error(`not a sandbox domain: ${JSON.stringify(domain)}`);
148
- return domain.toLowerCase();
149
- }),
150
- );
176
+ const network = unique(list(spec.network, "network").map((d) => (d as string).toLowerCase()));
151
177
  // The most specific path naming a directory decides whether it is writable.
152
178
  const writableAt = (path: string) => writableIn({ read, write }, path);
153
179
  /** Each gitdir, and whether a writable worktree reaches it as its own or as a linked one's. */
@@ -218,6 +244,44 @@ export async function resolveSandbox(
218
244
  };
219
245
  }
220
246
 
247
+ /**
248
+ * A whole run's box (`awf run --in`): a sandbox spec without `cwd` or `key`, resolved as one is, and
249
+ * `hide`, paths in its reach nothing inside reads or writes. They are resolved where they will be,
250
+ * as a missing one may appear. The run root is the box's to write: never hidden, nor hid.
251
+ */
252
+ export async function resolveRunBox(
253
+ given: unknown,
254
+ options: Omit<ResolveOptions, "key" | "inline">,
255
+ ): Promise<SandboxResolution> {
256
+ if (!isRecord(given)) throw new Error("a box spec must be an object");
257
+ for (const [field, why] of Object.entries(NOT_IN_A_BOX)) {
258
+ if (field in given) throw new Error(`a box names no ${field}; ${why}`);
259
+ }
260
+ const { hide, ...spec } = given;
261
+ const resolved = await resolveSandbox(spec, { ...options, key: "box" });
262
+ const home = await realpath(options.home ?? homedir());
263
+ const runRoot = await realpath(options.runRoot);
264
+ const hidden = await Promise.all(
265
+ list(hide, "hide").map(async (path) => {
266
+ checkPath(path, "hide");
267
+ const expanded =
268
+ path === "~" ? home : path.startsWith("~/") ? join(home, path.slice(2)) : path;
269
+ const at = await realpathMissing(resolve(resolved.sandbox.cwd, expanded));
270
+ if (contains(at, resolved.sandbox.cwd))
271
+ throw new Error(`box hide ${path} holds the run's working directory`);
272
+ if (contains(at, runRoot)) throw new Error(`box hide ${path} holds the run root`);
273
+ return at;
274
+ }),
275
+ );
276
+ return { ...resolved, sandbox: { ...resolved.sandbox, hidden: unique(hidden) } };
277
+ }
278
+
279
+ const NOT_IN_A_BOX = {
280
+ cwd: "it works in --cwd",
281
+ key: "a run has one box",
282
+ provider: 'its provider is its setting, such as "srt": {}',
283
+ };
284
+
221
285
  /**
222
286
  * Whether `path` is writable in this reach: the most specific of `read` and `write` holding it
223
287
  * decides. The working directory is readable, but never more specific than a `write` holding it.
@@ -358,18 +422,23 @@ export async function repositoryOf(path: string, home: string): Promise<Reposito
358
422
  return undefined;
359
423
  }
360
424
 
361
- async function resolvePath(
362
- path: unknown,
363
- base: string,
364
- home: string,
365
- field: string,
366
- ): Promise<string> {
425
+ /** A sandbox path's shape: a non-empty string, `~` only as the operator's home. */
426
+ function checkPath(path: unknown, field: string): asserts path is string {
367
427
  if (typeof path !== "string" || path.trim() === "") {
368
428
  throw new Error(`sandbox ${field} needs a non-empty path, not ${JSON.stringify(path)}`);
369
429
  }
370
430
  if (path.startsWith("~") && path !== "~" && !path.startsWith("~/")) {
371
431
  throw new Error(`sandbox ${field} ${path}: only ~ and ~/ expand, to the operator's home`);
372
432
  }
433
+ }
434
+
435
+ async function resolvePath(
436
+ path: unknown,
437
+ base: string,
438
+ home: string,
439
+ field: string,
440
+ ): Promise<string> {
441
+ checkPath(path, field);
373
442
  const expanded = path === "~" ? home : path.startsWith("~/") ? join(home, path.slice(2)) : path;
374
443
  const absolute = isAbsolute(expanded) ? expanded : resolve(base, expanded);
375
444
  try {
package/src/seam.ts CHANGED
@@ -26,8 +26,32 @@ export interface SandboxProvider<E> {
26
26
  * every release.
27
27
  */
28
28
  open(spec: ResolvedSandbox<E>, context: SandboxContext): Promise<OpenedSandbox>;
29
+ /**
30
+ * Present where the provider can hold a whole run (`awf run --in`): the command, to put before a
31
+ * process's argv, that runs it inside `box` with the engine's and the harnesses' needs added.
32
+ * Holds the whole spec, or rejects naming what it cannot hold.
33
+ */
34
+ box?(box: ResolvedSandbox<E>, context: RunBoxContext): Promise<readonly string[]>;
29
35
  }
30
36
 
37
+ /** What a whole run's box holds beyond its spec: what the engine and its agents need. */
38
+ export type RunBoxContext = {
39
+ /** The box's own folder, its home and temp inside: read and written. */
40
+ directory: string;
41
+ /** Where the run's records go: read and written. */
42
+ runRoot: string;
43
+ /** The engine's sockets, `AWF_CONTROL_ROOT`: written, its sockets bound and reached. */
44
+ controlRoot: string;
45
+ /** What the engine runs on, read: bun, awf's install, a preload, the workflow's packages. */
46
+ toolchain: readonly string[];
47
+ /** The harnesses whose logins the box carries. */
48
+ harnesses: readonly Pick<
49
+ HarnessSandboxNeeds,
50
+ "domains" | "executable" | "reads" | "sharedWrites"
51
+ >[];
52
+ deadline: AbsoluteDeadline;
53
+ };
54
+
31
55
  /** The providers an operator installed, keyed by the environment name a spec uses for each. */
32
56
  export type SandboxProviders = {
33
57
  readonly installed: Readonly<Partial<Record<SandboxEnvironmentKey, SandboxProvider<unknown>>>>;
package/src/srt/index.ts CHANGED
@@ -32,6 +32,8 @@ import { removeSecrets, shellQuote, writeSecrets } from "../secrets";
32
32
  import {
33
33
  agentProfile,
34
34
  baseProfile,
35
+ boxProfile,
36
+ checkBoxProfile,
35
37
  checkProfile,
36
38
  DENIED,
37
39
  type SrtHost,
@@ -47,6 +49,8 @@ export type SrtOptions = SrtHost & {
47
49
  probe?: boolean;
48
50
  };
49
51
 
52
+ /** The command a refusal names when srt is missing or does not run. */
53
+ const INSTALL = "npm i -g @anthropic-ai/sandbox-runtime";
50
54
  /** How long `srt --version` may take before srt is taken to be missing. */
51
55
  const VERSION_MS = 10_000;
52
56
  /** The longest a `setTimeout` waits: above it, the timer fires at once. */
@@ -78,17 +82,28 @@ export function createSrtProvider(options: SrtOptions): SandboxProvider<SrtEnvir
78
82
  }
79
83
  return {};
80
84
  },
81
- async open(spec, context) {
82
- // srt applies every allow, then every deny: a `write` inside a `read` inside a `write`
83
- // would be denied, narrower than the spec says.
84
- for (const path of spec.write) {
85
- const read = spec.read.find((root) => root !== path && contains(root, path));
86
- if (read && spec.write.some((root) => root !== read && contains(root, read))) {
87
- throw new Error(
88
- `srt cannot make ${path} writable inside ${read}, read-only inside a write`,
89
- );
90
- }
85
+ async box(spec, context) {
86
+ checkNesting(spec);
87
+ // A folder empty as the box opens is the run's to fill, as a trial's scratch folder is: no
88
+ // tool of the host's works there yet, and srt, guarding a path, refuses to make the folders
89
+ // above it, so a checkout holding `.claude/` could not be made there.
90
+ const fresh = await emptyOf(spec.write);
91
+ const guarded = (await protectedPaths(spec)).filter(
92
+ (path) => !fresh.some((root) => contains(root, path)),
93
+ );
94
+ const settings = boxProfile(spec, context, options, guarded);
95
+ checkBoxProfile(settings, options, spec);
96
+ if (options.probe !== false) await probed(context);
97
+ for (const harness of context.harnesses) {
98
+ for (const shared of harness.sharedWrites ?? []) await sharedDirectory(shared);
91
99
  }
100
+ // In the box's folder, which the box writes: srt reads it once, as it starts.
101
+ const profile = join(context.directory, `box-${randomUUID()}.json`);
102
+ await writeFile(profile, JSON.stringify(settings, null, 2), { mode: 0o600 });
103
+ return [...options.command, "-s", profile, "--"];
104
+ },
105
+ async open(spec, context) {
106
+ checkNesting(spec);
92
107
  const temp = join(context.directory, "tmp");
93
108
  const base = baseProfile(spec, context, options, temp, await protectedPaths(spec));
94
109
  checkProfile(base, options, context, spec);
@@ -100,6 +115,27 @@ export function createSrtProvider(options: SrtOptions): SandboxProvider<SrtEnvir
100
115
  };
101
116
  }
102
117
 
118
+ /** Each of `paths` that is a folder holding nothing. */
119
+ async function emptyOf(paths: readonly string[]): Promise<string[]> {
120
+ const empty = await Promise.all(
121
+ paths.map(async (path) => (await readdir(path).catch(() => [undefined])).length === 0),
122
+ );
123
+ return paths.filter((_, index) => empty[index]);
124
+ }
125
+
126
+ /**
127
+ * srt applies every allow, then every deny: a `write` inside a `read` inside a `write` would be
128
+ * denied, narrower than the spec says.
129
+ */
130
+ function checkNesting(spec: ResolvedSandbox<unknown>): void {
131
+ for (const path of spec.write) {
132
+ const read = spec.read.find((root) => root !== path && contains(root, path));
133
+ if (read && spec.write.some((root) => root !== read && contains(root, read))) {
134
+ throw new Error(`srt cannot make ${path} writable inside ${read}, read-only inside a write`);
135
+ }
136
+ }
137
+ }
138
+
103
139
  function openSandbox(
104
140
  spec: ResolvedSandbox<unknown>,
105
141
  context: SandboxContext,
@@ -329,17 +365,17 @@ async function probe(options: SrtOptions, context: SandboxContext): Promise<void
329
365
 
330
366
  /**
331
367
  * srt as installed on this machine: the `srt` on `PATH` that answers `--version` (npm releases are
332
- * 0.0.x; older ones print 1.0.0 outside npm). `undefined` when absent. The
333
- * toolchain is what `PATH`'s executables under `~` need: their `bin` directories, and each one's
334
- * install tree (X19): a node package's root, a `bin/` beside a `lib/` (a node or a Python venv),
335
- * or the executable alone. Never a whole parent of `bin`: `~/.local` holds `state/` and
336
- * credentials, and `~/.orbstack` an SSH key.
368
+ * 0.0.x; older ones print 1.0.0 outside npm). Refused when missing or broken, saying where it
369
+ * looked and the command that installs it. The toolchain is what `PATH`'s executables under `~`
370
+ * need: their `bin` directories, and each one's install tree (X19): a node package's root, a
371
+ * `bin/` beside a `lib/` (a node or a Python venv), or the executable alone. Never a whole parent
372
+ * of `bin`: `~/.local` holds `state/` and credentials, and `~/.orbstack` an SSH key.
337
373
  */
338
374
  export async function findSrt(
339
375
  environment: Readonly<Record<string, string | undefined>>,
340
376
  harnessState: readonly string[],
341
377
  platform: NodeJS.Platform = process.platform,
342
- ): Promise<SrtOptions | undefined> {
378
+ ): Promise<SrtOptions> {
343
379
  // On Linux srt 0.0.81 loses a write nested in a read, git, the network with `/tmp` denied, and
344
380
  // every Unix socket, the door's among them (docs/findings/sandbox-providers.md, X24).
345
381
  if (platform !== "darwin") {
@@ -350,15 +386,23 @@ export async function findSrt(
350
386
  const path = (environment.PATH ?? "").split(":").filter(Boolean);
351
387
  const cli = await firstExecutable("srt", path);
352
388
  const node = await firstExecutable("node", path);
353
- if (!cli || !node) return undefined;
389
+ // A global npm install lives under one node: switching node, as mise or nvm does, loses it.
390
+ if (!cli && !node) throw new Error(`no srt or node on PATH; install node, then srt: ${INSTALL}`);
391
+ if (!node) throw new Error(`srt is on PATH at ${cli}, but no node is, which srt runs on`);
392
+ if (!cli) throw new Error(`no srt on PATH; install it under the node there, ${node}: ${INSTALL}`);
354
393
  const version = Bun.spawnSync({
355
394
  cmd: [node, cli, "--version"],
356
395
  stdout: "pipe",
357
396
  stderr: "pipe",
358
397
  timeout: VERSION_MS,
359
398
  });
360
- if (version.exitCode !== 0 || !/^\d+\.\d+\.\d+/.test(version.stdout.toString().trim()))
361
- return undefined;
399
+ if (version.exitCode !== 0 || !/^\d+\.\d+\.\d+/.test(version.stdout.toString().trim())) {
400
+ const said = version.stderr.toString().trim().split("\n")[0]?.trim();
401
+ throw new Error(
402
+ `${cli} --version failed under ${node}${said ? ` (${said})` : ""}; ` +
403
+ `install it under that node: ${INSTALL}`,
404
+ );
405
+ }
362
406
  const real = [
363
407
  ...new Set(
364
408
  (await Promise.all(path.map((entry) => realpath(entry).catch(() => undefined)))).filter(
@@ -1,6 +1,6 @@
1
1
  import { dirname, join } from "node:path";
2
2
  import { contains, KEY_DIRECTORIES } from "../resolve";
3
- import type { AgentContext, ResolvedSandbox, SandboxContext } from "../seam";
3
+ import type { AgentContext, ResolvedSandbox, RunBoxContext, SandboxContext } from "../seam";
4
4
 
5
5
  /** srt's settings file, as much of it as a sandbox uses. */
6
6
  export type SrtSettings = {
@@ -194,6 +194,99 @@ export function checkProfile(
194
194
  }
195
195
  }
196
196
 
197
+ /**
198
+ * A whole run's profile (`awf run --in`): the spec's reach as a sandbox's base has it, and what the
199
+ * engine and the logged-in harnesses need: the run root, the box's folder and the control root
200
+ * written, the toolchain and each harness's install read, its domains reached. A hidden path wins
201
+ * over every allowed one: nothing that lies in it is allowed, nor its gitdir.
202
+ */
203
+ export function boxProfile(
204
+ spec: ResolvedSandbox<unknown>,
205
+ context: RunBoxContext,
206
+ host: SrtHost,
207
+ /** What the host runs or follows, which nothing in the box writes: `protectedPaths`. */
208
+ protectedGit: readonly string[],
209
+ ): SrtSettings {
210
+ const shown = (path: string) => !spec.hidden.some((hidden) => contains(hidden, path));
211
+ const shared = context.harnesses.flatMap((harness) => harness.sharedWrites ?? []);
212
+ const writes = unique([
213
+ ...spec.write,
214
+ ...spec.gitdirs.filter((gitdir) => gitdir.writable).map((gitdir) => gitdir.path),
215
+ context.directory,
216
+ context.runRoot,
217
+ context.controlRoot,
218
+ ...shared,
219
+ ]).filter(shown);
220
+ // A path written under `/private/tmp` is named through `/tmp` too, as cursor names its own; the
221
+ // link alone opens nothing behind it.
222
+ const tmpLink = writes.some((path) => contains("/private/tmp", path)) ? ["/tmp"] : [];
223
+ return {
224
+ enableWeakerNetworkIsolation: true,
225
+ network: {
226
+ allowedDomains: unique([
227
+ ...spec.network,
228
+ ...context.harnesses.flatMap((harness) => harness.domains),
229
+ ]),
230
+ deniedDomains: [],
231
+ allowUnixSockets: unique([...spec.sockets, context.controlRoot]),
232
+ },
233
+ filesystem: {
234
+ denyRead: unique([host.home, ...DENIED, ...spec.hidden]),
235
+ allowRead: unique([
236
+ spec.cwd,
237
+ ...spec.read,
238
+ ...spec.gitdirs.map((gitdir) => gitdir.path),
239
+ ...context.toolchain,
240
+ ...host.toolchain,
241
+ ...(host.xcrunCache ? [host.xcrunCache] : []),
242
+ ...context.harnesses.flatMap((harness) => [harness.executable, ...harness.reads]),
243
+ ...writes,
244
+ ...tmpLink,
245
+ ]).filter(shown),
246
+ allowWrite: writes,
247
+ denyWrite: unique([
248
+ ...spec.hidden,
249
+ ...protectedGit,
250
+ ...spec.read.filter((path) =>
251
+ spec.write.some((root) => root !== path && contains(root, path)),
252
+ ),
253
+ ]),
254
+ },
255
+ };
256
+ }
257
+
258
+ /**
259
+ * The pure check a box's profile passes before srt sees it: `~` denied, each hidden path denied for
260
+ * reads and writes, and no allowed path exposing `~`, a key directory or the operator's harness
261
+ * state, nor writing into that state. An install tree may lie inside harness state, never hold it.
262
+ */
263
+ export function checkBoxProfile(
264
+ settings: SrtSettings,
265
+ host: SrtHost,
266
+ { hidden }: Pick<ResolvedSandbox<unknown>, "hidden">,
267
+ ): void {
268
+ const { denyRead, allowRead, allowWrite, denyWrite } = settings.filesystem;
269
+ if (!denyRead.includes(host.home)) throw new Error(`srt box does not deny ${host.home}`);
270
+ for (const path of hidden) {
271
+ if (!denyRead.includes(path) || !denyWrite.includes(path)) {
272
+ throw new Error(`srt box does not hide ${path}`);
273
+ }
274
+ }
275
+ for (const path of [...allowRead, ...allowWrite]) {
276
+ if (contains(path, host.home)) throw new Error(`srt box would expose ~ through ${path}`);
277
+ const state = host.harnessState.find((root) => contains(path, root));
278
+ if (state) throw new Error(`srt box would expose harness state ${state} through ${path}`);
279
+ const keys = KEY_DIRECTORIES.map((name) => join(host.home, name)).find(
280
+ (root) => contains(path, root) || contains(root, path),
281
+ );
282
+ if (keys) throw new Error(`srt box would expose ${keys} through ${path}`);
283
+ }
284
+ for (const path of allowWrite) {
285
+ const state = host.harnessState.find((root) => contains(root, path));
286
+ if (state) throw new Error(`srt box would let ${path} in harness state be written`);
287
+ }
288
+ }
289
+
197
290
  function unique(values: readonly string[]): string[] {
198
291
  return [...new Set(values)];
199
292
  }