@agentswf/sandbox 0.1.0-beta.2 → 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 +9 -1
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
|
);
|