@agentswf/sandbox 0.1.0-beta.2 → 0.1.0-beta.4

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,9 +1,9 @@
1
1
  {
2
2
  "name": "@agentswf/sandbox",
3
- "version": "0.1.0-beta.2",
3
+ "version": "0.1.0-beta.4",
4
4
  "description": "agents.wf: the sandboxes a workflow opens, and their providers",
5
5
  "license": "MIT",
6
- "homepage": "https://github.com/romanlv/agentswf",
6
+ "homepage": "https://agents.wf",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "git+https://github.com/romanlv/agentswf.git",
@@ -28,7 +28,7 @@
28
28
  "docker"
29
29
  ],
30
30
  "dependencies": {
31
- "@agentswf/contract": "0.1.0-beta.2"
31
+ "@agentswf/contract": "0.1.0-beta.4"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public"
@@ -493,8 +493,6 @@ async function admitAgent(
493
493
  agent.door.boxScript,
494
494
  );
495
495
  const agentId = randomUUID();
496
- const relay = await startRelay(client, box, agent.door.endpoint, `/run/awf-relay/${agentId}`);
497
- const pids = `${BOX_PIDS}/${agentId}`;
498
496
  // A box's `/tmp` is its own; its co-tenants share the agent's uid, as they share everything.
499
497
  const short = agent.harness.shortDirectory ? `/tmp/awf-${agentId.slice(0, 8)}` : undefined;
500
498
  if (short) {
@@ -505,6 +503,9 @@ async function admitAgent(
505
503
  throw new Error(`docker: making ${short} failed in the box: ${made.stderr.trim()}`);
506
504
  }
507
505
  }
506
+ // Last, as no release follows an admit that fails, and the relay would run until awf exits.
507
+ const relay = await startRelay(client, box, agent.door.endpoint, `/run/awf-relay/${agentId}`);
508
+ const pids = `${BOX_PIDS}/${agentId}`;
508
509
  const env: Record<string, string> = {
509
510
  HOME: agent.home,
510
511
  ...agent.harness.env,
package/src/resolve.ts CHANGED
@@ -8,7 +8,7 @@ import type { Gitdir, ResolvedSandbox, SandboxProviders } from "./seam";
8
8
  const REACH_KEYS = ["read", "write", "network", "sockets", "webSearch"] as const;
9
9
 
10
10
  export type SandboxResolution = {
11
- /** The environment key the sandbox runs under: the one the spec named, else the default. */
11
+ /** The environment key the sandbox runs under, the one the spec named. */
12
12
  provider: SandboxEnvironmentKey;
13
13
  sandbox: ResolvedSandbox<unknown>;
14
14
  };
@@ -37,6 +37,11 @@ export type ResolveOptions = {
37
37
  * another agent's launcher, which runs on the host.
38
38
  */
39
39
  controlRoot?: string;
40
+ /**
41
+ * Where holders reach live runs' coordinators, which `AWF_COORDINATOR_DIR` may move out of
42
+ * `~/.awf`: no sandbox path may contain it or lie inside it.
43
+ */
44
+ coordinatorRoot?: string;
40
45
  };
41
46
 
42
47
  /**
@@ -65,8 +70,10 @@ export async function resolveSandbox(
65
70
  if (named.length > 1) {
66
71
  throw new Error(`a sandbox has one environment, not ${named.join(" and ")}`);
67
72
  }
68
- const provider = named[0] ?? options.providers.default;
69
- if (provider === undefined) throw new Error("no sandbox provider is installed");
73
+ const provider = named[0];
74
+ if (provider === undefined) {
75
+ throw new Error('a sandbox spec names its provider: add "srt": {} or "docker": {}');
76
+ }
70
77
  const installed = options.providers.installed[provider];
71
78
  if (!installed) {
72
79
  const why = options.providers.unavailable?.[provider];
@@ -74,7 +81,7 @@ export async function resolveSandbox(
74
81
  `the ${provider} sandbox provider is not ${why ? `usable: ${why}` : "installed"}`,
75
82
  );
76
83
  }
77
- const environment = installed.environment(named[0] === undefined ? {} : spec[named[0]]);
84
+ const environment = installed.environment(spec[provider]);
78
85
 
79
86
  const home = await realpath(options.home ?? homedir());
80
87
  const runRoot = await realpath(options.runRoot);
@@ -83,6 +90,10 @@ export async function resolveSandbox(
83
90
  options.controlRoot === undefined
84
91
  ? undefined
85
92
  : await realpath(options.controlRoot).catch(() => options.controlRoot);
93
+ const coordinatorRoot =
94
+ options.coordinatorRoot === undefined
95
+ ? undefined
96
+ : await realpath(options.coordinatorRoot).catch(() => options.coordinatorRoot);
86
97
  const harnessState = await Promise.all(
87
98
  options.harnessState.map((path) => realpath(path).catch(() => path)),
88
99
  );
@@ -101,6 +112,8 @@ export async function resolveSandbox(
101
112
  if (keys) throw new Error(`sandbox ${field} ${path} would expose keys in ${keys}`);
102
113
  if (contains(machine, path))
103
114
  throw new Error(`sandbox ${field} ${path} would expose ${machine}`);
115
+ if (coordinatorRoot && (contains(path, coordinatorRoot) || contains(coordinatorRoot, path)))
116
+ throw new Error(`sandbox ${field} ${path} would expose the coordinator sockets`);
104
117
  if (controlRoot && (contains(path, controlRoot) || insideDoors(controlRoot, path))) {
105
118
  throw new Error(`sandbox ${field} ${path} would expose the engine's doors`);
106
119
  }
package/src/seam.ts CHANGED
@@ -31,8 +31,6 @@ export interface SandboxProvider<E> {
31
31
  /** The providers an operator installed, keyed by the environment name a spec uses for each. */
32
32
  export type SandboxProviders = {
33
33
  readonly installed: Readonly<Partial<Record<SandboxEnvironmentKey, SandboxProvider<unknown>>>>;
34
- /** The environment a spec that names none runs in; absent when nothing is installed. */
35
- readonly default?: SandboxEnvironmentKey;
36
34
  /** Why a provider this machine has could not be set up: said when a spec names it. */
37
35
  readonly unavailable?: Readonly<Partial<Record<SandboxEnvironmentKey, string>>>;
38
36
  };
@@ -159,7 +157,7 @@ export type AgentDoor = {
159
157
  launcher: string;
160
158
  /** The launcher's contents for a box, copied to `launcher` inside it: `bundle` run by `bun` from `PATH`. */
161
159
  boxScript: string;
162
- /** The bundled `wf` command, a host file copied to the same path inside a box. */
160
+ /** The bundled `wfa` command, a host file copied to the same path inside a box. */
163
161
  bundle: string;
164
162
  /** Host paths the host launcher reads: its interpreter and the bundle. */
165
163
  reads: readonly string[];
package/src/srt/index.ts CHANGED
@@ -141,7 +141,7 @@ function openSandbox(
141
141
  HOME: options.home,
142
142
  PATH: [...options.path, ...SYSTEM_PATH].join(":"),
143
143
  CLAUDE_CODE_TMPDIR: temp,
144
- // The `wf result <<'WF_JSON'` every prompt asks for needs a heredoc's temp file. zsh
144
+ // The `wfa result <<'WF_JSON'` every prompt asks for needs a heredoc's temp file. zsh
145
145
  // writes it under `TMPPREFIX`, `/tmp/zsh` by default, which is denied; macOS's bash 3.2
146
146
  // writes it in `/var/tmp` whatever `TMPDIR` says, which is denied too (X22). So the
147
147
  // harnesses' shell is zsh, its heredocs in the sandbox's temp.
@@ -278,9 +278,17 @@ async function probe(options: SrtOptions, context: SandboxContext): Promise<void
278
278
  env: { PATH: SYSTEM_PATH.join(":"), HOME: options.home },
279
279
  stdout: "pipe",
280
280
  stderr: "pipe",
281
+ // Its own group, so the timeout stops the sandbox and what runs in it, not srt alone.
282
+ detached: true,
281
283
  });
282
284
  const timer = setTimeout(
283
- () => child.kill("SIGKILL"),
285
+ () => {
286
+ try {
287
+ process.kill(-child.pid, "SIGKILL");
288
+ } catch {
289
+ // It ended meanwhile.
290
+ }
291
+ },
284
292
  // A timer overflows past 2^31 - 1 ms, and would fire at once.
285
293
  Math.min(Math.max(0, context.deadline.unixMilliseconds - Date.now()), 2_147_483_647),
286
294
  );
@@ -94,7 +94,7 @@ export function sandboxConformance(name: string, setup: ConformanceSetup | undef
94
94
  {
95
95
  read: reach.read,
96
96
  write: reach.write,
97
- ...(environment ? { [environment.key]: environment.settings } : {}),
97
+ [environment?.key ?? "srt"]: environment?.settings ?? {},
98
98
  },
99
99
  {
100
100
  key,
@@ -104,7 +104,6 @@ export function sandboxConformance(name: string, setup: ConformanceSetup | undef
104
104
  harnessState: [],
105
105
  providers: {
106
106
  installed: { [environment?.key ?? "srt"]: setup.provider },
107
- default: environment?.key ?? "srt",
108
107
  },
109
108
  },
110
109
  );
@@ -341,7 +340,7 @@ async function openDoor(servers: Server[], directories: string[]): Promise<Agent
341
340
  directories.push(directory);
342
341
  const endpoint = join(directory, "s.sock");
343
342
  const bundle = join(directory, "door.js");
344
- const launcher = join(directory, "wf");
343
+ const launcher = join(directory, "wfa");
345
344
  const server = createServer({ allowHalfOpen: true }, (socket) => {
346
345
  let said = "";
347
346
  socket.on("data", (data) => {