@agentswf/sandbox 0.1.0-beta.1 → 0.1.0-beta.3
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 +2 -2
- package/src/docker/index.ts +3 -2
- package/src/resolve.ts +11 -0
- package/src/srt/index.ts +13 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentswf/sandbox",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.3",
|
|
4
4
|
"description": "agents.wf: the sandboxes a workflow opens, and their providers",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/romanlv/agentswf",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"docker"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@agentswf/contract": "0.1.0-beta.
|
|
31
|
+
"@agentswf/contract": "0.1.0-beta.3"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|
package/src/docker/index.ts
CHANGED
|
@@ -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
|
@@ -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
|
/**
|
|
@@ -83,6 +88,10 @@ export async function resolveSandbox(
|
|
|
83
88
|
options.controlRoot === undefined
|
|
84
89
|
? undefined
|
|
85
90
|
: await realpath(options.controlRoot).catch(() => options.controlRoot);
|
|
91
|
+
const coordinatorRoot =
|
|
92
|
+
options.coordinatorRoot === undefined
|
|
93
|
+
? undefined
|
|
94
|
+
: await realpath(options.coordinatorRoot).catch(() => options.coordinatorRoot);
|
|
86
95
|
const harnessState = await Promise.all(
|
|
87
96
|
options.harnessState.map((path) => realpath(path).catch(() => path)),
|
|
88
97
|
);
|
|
@@ -101,6 +110,8 @@ export async function resolveSandbox(
|
|
|
101
110
|
if (keys) throw new Error(`sandbox ${field} ${path} would expose keys in ${keys}`);
|
|
102
111
|
if (contains(machine, path))
|
|
103
112
|
throw new Error(`sandbox ${field} ${path} would expose ${machine}`);
|
|
113
|
+
if (coordinatorRoot && (contains(path, coordinatorRoot) || contains(coordinatorRoot, path)))
|
|
114
|
+
throw new Error(`sandbox ${field} ${path} would expose the coordinator sockets`);
|
|
104
115
|
if (controlRoot && (contains(path, controlRoot) || insideDoors(controlRoot, path))) {
|
|
105
116
|
throw new Error(`sandbox ${field} ${path} would expose the engine's doors`);
|
|
106
117
|
}
|
package/src/srt/index.ts
CHANGED
|
@@ -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
|
-
() =>
|
|
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
|
);
|
|
@@ -304,7 +312,8 @@ async function probe(options: SrtOptions, context: SandboxContext): Promise<void
|
|
|
304
312
|
}
|
|
305
313
|
|
|
306
314
|
/**
|
|
307
|
-
* srt as installed on this machine:
|
|
315
|
+
* srt as installed on this machine: the `srt` on `PATH` that answers `--version` (npm releases are
|
|
316
|
+
* 0.0.x; older ones print 1.0.0 outside npm). `undefined` when absent. The
|
|
308
317
|
* toolchain is what `PATH`'s executables under `~` need: their `bin` directories, and each one's
|
|
309
318
|
* install tree (X19): a node package's root, a `bin/` beside a `lib/` (a node or a Python venv),
|
|
310
319
|
* or the executable alone. Never a whole parent of `bin`: `~/.local` holds `state/` and
|
|
@@ -326,8 +335,8 @@ export async function findSrt(
|
|
|
326
335
|
stderr: "pipe",
|
|
327
336
|
timeout: VERSION_MS,
|
|
328
337
|
});
|
|
329
|
-
|
|
330
|
-
|
|
338
|
+
if (version.exitCode !== 0 || !/^\d+\.\d+\.\d+/.test(version.stdout.toString().trim()))
|
|
339
|
+
return undefined;
|
|
331
340
|
const real = [
|
|
332
341
|
...new Set(
|
|
333
342
|
(await Promise.all(path.map((entry) => realpath(entry).catch(() => undefined)))).filter(
|