@parcha/agentrun-computer 0.1.0-beta.38 → 0.1.0-beta.40
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/README.md +126 -83
- package/box/Dockerfile +5 -54
- package/box/README.md +9 -3
- package/box/build-daytona.py +2 -2
- package/box/build-e2b.mjs +1 -1
- package/box/install.sh +87 -0
- package/box/recipe.d.mts +5 -0
- package/box/recipe.mjs +12 -10
- package/dist/agent37.d.ts +17 -4
- package/dist/agent37.js +98 -17
- package/dist/box-image.d.ts +14 -0
- package/dist/box-image.js +24 -0
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/computerd.json +2 -2
- package/dist/conformance/agent37.d.ts +9 -4
- package/dist/conformance/agent37.js +23 -11
- package/dist/conformance/browserbase.js +3 -3
- package/dist/conformance/cases/apps.d.ts +1 -1
- package/dist/conformance/cases/apps.js +1 -1
- package/dist/conformance/cases/isolation.d.ts +18 -3
- package/dist/conformance/cases/isolation.js +73 -6
- package/dist/conformance/cases/lifetime.js +30 -0
- package/dist/conformance/cases/mount.js +4 -2
- package/dist/conformance/cases/provider.js +88 -1
- package/dist/conformance/cli.js +29 -9
- package/dist/conformance/e2b.js +9 -4
- package/dist/conformance/exec-stream.d.ts +44 -7
- package/dist/conformance/exec-stream.js +347 -88
- package/dist/conformance/kernel.js +2 -2
- package/dist/conformance/modal.js +1 -1
- package/dist/conformance/orgo.js +2 -2
- package/dist/conformance/report.js +3 -0
- package/dist/conformance/runner.js +127 -9
- package/dist/conformance/types.d.ts +21 -0
- package/dist/daytona.d.ts +0 -5
- package/dist/daytona.js +19 -28
- package/dist/descriptor.d.ts +5 -3
- package/dist/descriptors/agent37.d.ts +3 -11
- package/dist/descriptors/agent37.js +9 -10
- package/dist/descriptors/daytona.d.ts +1 -1
- package/dist/descriptors/daytona.js +5 -2
- package/dist/descriptors/docker.d.ts +13 -1
- package/dist/descriptors/docker.js +3 -1
- package/dist/descriptors/e2b.d.ts +2 -9
- package/dist/descriptors/e2b.js +8 -8
- package/dist/descriptors/index.d.ts +21 -19
- package/dist/descriptors/index.js +1 -3
- package/dist/descriptors/modal.d.ts +2 -6
- package/dist/descriptors/modal.js +8 -6
- package/dist/descriptors/orgo.js +2 -1
- package/dist/docker/egress-main.js +23 -15
- package/dist/docker/egress.d.ts +6 -4
- package/dist/docker/egress.js +24 -16
- package/dist/docker/inspect.d.ts +2 -2
- package/dist/docker/inspect.js +5 -5
- package/dist/docker.d.ts +6 -5
- package/dist/docker.js +12 -11
- package/dist/e2b.d.ts +12 -2
- package/dist/e2b.js +42 -19
- package/dist/host.d.ts +113 -59
- package/dist/host.js +5 -0
- package/dist/hosted/framed-exec.d.ts +49 -0
- package/dist/hosted/framed-exec.js +185 -0
- package/dist/hosted/network.d.ts +23 -0
- package/dist/hosted/network.js +77 -0
- package/dist/hosted/process.d.ts +13 -5
- package/dist/hosted/process.js +35 -12
- package/dist/hosted/provider.d.ts +16 -9
- package/dist/hosted/provider.js +475 -170
- package/dist/hosted/rest.d.ts +20 -2
- package/dist/hosted/rest.js +24 -10
- package/dist/hosted/scripts.d.ts +27 -7
- package/dist/hosted/scripts.js +77 -18
- package/dist/{agent37-ssh.d.ts → hosted/ssh-exec.d.ts} +19 -9
- package/dist/{agent37-ssh.js → hosted/ssh-exec.js} +38 -19
- package/dist/hosted/values.d.ts +21 -0
- package/dist/hosted/values.js +55 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/isolation.d.ts +0 -2
- package/dist/isolation.js +3 -4
- package/dist/modal.d.ts +8 -2
- package/dist/modal.js +21 -15
- package/dist/mount-archil.d.ts +5 -4
- package/dist/mount-archil.js +5 -6
- package/dist/orgo.js +6 -4
- package/dist/providers.d.ts +4 -1
- package/dist/surface/api.d.ts +0 -9
- package/dist/surface/core.d.ts +7 -2
- package/dist/surface/core.js +12 -4
- package/dist/surface/index.d.ts +1 -1
- package/dist/surface/index.js +1 -1
- package/dist/surface/script.d.ts +4 -0
- package/dist/surface/script.js +9 -3
- package/package.json +1 -1
- package/box/build-agent37.mjs +0 -158
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
// exec for a vendor whose process comes in pieces: a call that starts it, a stream of its events, a call per write to
|
|
2
|
+
// its stdin, and, where the vendor has them, a call that ends its stdin and one that kills it. framedExec turns those
|
|
3
|
+
// pieces into the MachineProcess the adapter reads (../host.ts, exec), so a vendor writes only its own calls. It owns
|
|
4
|
+
// the rest: the writes go one call after another, in order, each answered before the next starts; output becomes
|
|
5
|
+
// bytes, its events read no faster than the caller reads it; and a vendor with no kill gets one by pid. PROVIDERS.md, "Exec shapes that work", has a worked example.
|
|
6
|
+
import { once } from "node:events";
|
|
7
|
+
import { PassThrough } from "node:stream";
|
|
8
|
+
/**
|
|
9
|
+
* The sh a process starts under when the vendor has no kill: one line on stderr, its pid and its start time (field 22
|
|
10
|
+
* of /proc/<pid>/stat, counted past the command's name in parentheses, which may hold spaces), then the command in its
|
|
11
|
+
* place, which keeps both.
|
|
12
|
+
*/
|
|
13
|
+
export const PID_WRAPPER = ["sh", "-c", 'echo "$$ $(s=$(cat /proc/$$/stat) && set -- ${s##*") "} && echo "${20}")" >&2; exec "$@"', "sh"];
|
|
14
|
+
/**
|
|
15
|
+
* The sh kill() starts, given the pid and start time: a pid whose process has ended, and may be another's now, is let
|
|
16
|
+
* be. Otherwise it kills the process and every process under it (an upload's head and base64 would wait on the open
|
|
17
|
+
* stdin, and hold stderr open, past their sh): each is stopped as it is found, so none forks away, by its parent pid
|
|
18
|
+
* (field 4 of its stat) until a pass over /proc finds no more, and then all are killed.
|
|
19
|
+
*/
|
|
20
|
+
export const PID_KILL = [
|
|
21
|
+
"pid=$1 start=$2",
|
|
22
|
+
'read -r s 2>/dev/null <"/proc/$pid/stat" || exit 0',
|
|
23
|
+
'set -- ${s##*") "}',
|
|
24
|
+
'[ "${20}" = "$start" ] || exit 0',
|
|
25
|
+
'kill -STOP "$pid" 2>/dev/null',
|
|
26
|
+
'all=" $pid " new=$pid',
|
|
27
|
+
'while [ -n "$new" ]; do',
|
|
28
|
+
"\tnew=",
|
|
29
|
+
"\tfor f in /proc/[0-9]*/stat; do",
|
|
30
|
+
'\t\tread -r s 2>/dev/null <"$f" || continue',
|
|
31
|
+
"\t\tp=${s%% *}",
|
|
32
|
+
'\t\tset -- ${s##*") "}',
|
|
33
|
+
'\t\tcase "$all" in *" $p "*) continue ;; esac',
|
|
34
|
+
'\t\tcase "$all" in *" $2 "*) all="$all$p " new="$new $p"; kill -STOP "$p" 2>/dev/null ;; esac',
|
|
35
|
+
"\tdone",
|
|
36
|
+
"done",
|
|
37
|
+
"kill -KILL $all 2>/dev/null",
|
|
38
|
+
"exit 0",
|
|
39
|
+
].join("\n");
|
|
40
|
+
/** argv started through a vendor's pieces, as the MachineProcess exec answers. */
|
|
41
|
+
export async function framedExec(pieces, argv, ctx) {
|
|
42
|
+
const byPid = pieces.kill === undefined;
|
|
43
|
+
const handle = await pieces.start(byPid ? [...PID_WRAPPER, ...argv] : argv, ctx);
|
|
44
|
+
const stdout = new PassThrough();
|
|
45
|
+
const stderr = new PassThrough();
|
|
46
|
+
// ended: the events stopped, so output and writes are done with. exitRead: the process's own exit came among them; a
|
|
47
|
+
// stream that broke without one leaves a process that may still run, which kill() still ends by its pid.
|
|
48
|
+
let ended = false;
|
|
49
|
+
let exitRead = false;
|
|
50
|
+
const killed = new AbortController();
|
|
51
|
+
/**
|
|
52
|
+
* Output on: while its reader is behind (the stream's buffer full), the events wait, until it drains or kill(). A
|
|
53
|
+
* reader that let go (a stream destroyed) drops the rest, so the exit still comes.
|
|
54
|
+
*/
|
|
55
|
+
const push = async (stream, bytes) => {
|
|
56
|
+
if (stream.writableEnded || stream.destroyed || stream.write(bytes))
|
|
57
|
+
return;
|
|
58
|
+
// One signal for both waits, aborted after: the one that lost leaves no listener behind.
|
|
59
|
+
const waited = new AbortController();
|
|
60
|
+
const signal = AbortSignal.any([killed.signal, waited.signal]);
|
|
61
|
+
await Promise.race([once(stream, "drain", { signal }), once(stream, "close", { signal })]).catch(() => { });
|
|
62
|
+
waited.abort();
|
|
63
|
+
};
|
|
64
|
+
// With no vendor kill, stderr's first line is the pid and its start time: held until it ends, then the rest is the
|
|
65
|
+
// process's own.
|
|
66
|
+
let pidLine = byPid ? Buffer.alloc(0) : undefined;
|
|
67
|
+
let gotPid = () => { };
|
|
68
|
+
const pid = new Promise((done) => (gotPid = done));
|
|
69
|
+
const toStderr = async (bytes) => {
|
|
70
|
+
if (pidLine === undefined)
|
|
71
|
+
return push(stderr, bytes);
|
|
72
|
+
pidLine = Buffer.concat([pidLine, bytes]);
|
|
73
|
+
const at = pidLine.indexOf(0x0a);
|
|
74
|
+
if (at < 0)
|
|
75
|
+
return;
|
|
76
|
+
gotPid(pidLine.subarray(0, at).toString("latin1").trim());
|
|
77
|
+
const rest = pidLine.subarray(at + 1);
|
|
78
|
+
pidLine = undefined;
|
|
79
|
+
if (rest.length > 0)
|
|
80
|
+
await push(stderr, rest);
|
|
81
|
+
};
|
|
82
|
+
const exited = (async () => {
|
|
83
|
+
let code = -1;
|
|
84
|
+
try {
|
|
85
|
+
for await (const event of pieces.events(handle)) {
|
|
86
|
+
if ("exit" in event) {
|
|
87
|
+
code = event.exit;
|
|
88
|
+
exitRead = true;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
const bytes = "text" in event ? Buffer.from(event.text, "utf8") : Buffer.from(event.base64, "base64");
|
|
92
|
+
if (event.stream === "stdout")
|
|
93
|
+
await push(stdout, bytes);
|
|
94
|
+
else
|
|
95
|
+
await toStderr(bytes);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
// A stream that broke: no exit code was read.
|
|
100
|
+
}
|
|
101
|
+
ended = true;
|
|
102
|
+
gotPid(undefined);
|
|
103
|
+
stdout.end();
|
|
104
|
+
stderr.end();
|
|
105
|
+
return code;
|
|
106
|
+
})();
|
|
107
|
+
// The writes as one queue: each call starts once the one before it answered, and one that failed fails every one after.
|
|
108
|
+
// ignoreBOM: a U+FEFF that starts stdin is text like any other, never a mark to drop.
|
|
109
|
+
const decoder = new TextDecoder("utf-8", { ignoreBOM: true });
|
|
110
|
+
let queue = Promise.resolve();
|
|
111
|
+
const send = (text) => {
|
|
112
|
+
if (ended)
|
|
113
|
+
return Promise.reject(new Error("the process has ended"));
|
|
114
|
+
const sent = queue.then(() => (text === "" ? undefined : pieces.write(handle, text)));
|
|
115
|
+
sent.catch(() => { });
|
|
116
|
+
queue = sent;
|
|
117
|
+
return sent;
|
|
118
|
+
};
|
|
119
|
+
/** "<pid> <start time>", once stderr's first line gives it; undefined once the process ended, or past ctx's bound. */
|
|
120
|
+
const pidWithin = async () => {
|
|
121
|
+
let timer;
|
|
122
|
+
const late = new Promise((done) => (timer = setTimeout(() => done(undefined), ctx.timeoutMs)));
|
|
123
|
+
try {
|
|
124
|
+
return await Promise.race([pid, late]);
|
|
125
|
+
}
|
|
126
|
+
finally {
|
|
127
|
+
clearTimeout(timer);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
return {
|
|
131
|
+
stdout,
|
|
132
|
+
stderr,
|
|
133
|
+
write: (bytes) => send(decoder.decode(bytes, { stream: true })),
|
|
134
|
+
end: async () => {
|
|
135
|
+
// A process that has ended, as one that read all it wanted can before its end (the upload), has no stdin to end.
|
|
136
|
+
if (ended)
|
|
137
|
+
return;
|
|
138
|
+
await send(decoder.decode());
|
|
139
|
+
await pieces.end?.(handle);
|
|
140
|
+
},
|
|
141
|
+
wait: () => exited,
|
|
142
|
+
kill: async () => {
|
|
143
|
+
killed.abort();
|
|
144
|
+
try {
|
|
145
|
+
if (pieces.kill)
|
|
146
|
+
await pieces.kill(handle);
|
|
147
|
+
else {
|
|
148
|
+
// Not once its exit was read; and after a stream that broke, only while the pid still has its start time: by
|
|
149
|
+
// then the pid may be another process's.
|
|
150
|
+
const target = /^([1-9][0-9]*) ([0-9]+)$/.exec((await pidWithin()) ?? "");
|
|
151
|
+
if (target !== null && !exitRead) {
|
|
152
|
+
const killer = await pieces.start(["sh", "-c", PID_KILL, "sh", target[1], target[2]], { timeoutMs: ctx.timeoutMs });
|
|
153
|
+
for await (const event of pieces.events(killer))
|
|
154
|
+
if ("exit" in event)
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
// Best effort: kill never throws.
|
|
161
|
+
}
|
|
162
|
+
stdout.end();
|
|
163
|
+
stderr.end();
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
/** The JSON value of each line of a body of newline-delimited JSON, as the lines come; a line that is not JSON throws. */
|
|
168
|
+
export async function* ndjson(body) {
|
|
169
|
+
const decoder = new TextDecoder();
|
|
170
|
+
let rest = "";
|
|
171
|
+
for await (const chunk of body) {
|
|
172
|
+
rest += decoder.decode(chunk, { stream: true });
|
|
173
|
+
let at = rest.indexOf("\n");
|
|
174
|
+
while (at >= 0) {
|
|
175
|
+
const line = rest.slice(0, at).trim();
|
|
176
|
+
rest = rest.slice(at + 1);
|
|
177
|
+
if (line !== "")
|
|
178
|
+
yield JSON.parse(line);
|
|
179
|
+
at = rest.indexOf("\n");
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
rest += decoder.decode();
|
|
183
|
+
if (rest.trim() !== "")
|
|
184
|
+
yield JSON.parse(rest);
|
|
185
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AllowCapability, NetworkForm, NetworkPolicy, NetworkSpec } from "../provider.js";
|
|
2
|
+
/** The label a computer whose network is open or a list carries: its form, as init was given it. None carries none. */
|
|
3
|
+
export declare const NETWORK_LABEL = "agentrun.computer.network";
|
|
4
|
+
/** Where init's proxy listens, and where it writes the form it serves (daemon/internal/egress/serve.go). */
|
|
5
|
+
export declare const EGRESS_PROXY_SOCKET: string;
|
|
6
|
+
export declare const EGRESS_POLICY: string;
|
|
7
|
+
/** The uid and gid init's proxy runs as, nobody (serve.go ProxyUser): no computer's user under open or a list may be it. */
|
|
8
|
+
export declare const EGRESS_PROXY_USER = 65534;
|
|
9
|
+
/** Init's relay on its programs' own loopback, which carries each connection to the proxy (daemon/internal/egress). */
|
|
10
|
+
export declare const EGRESS_RELAY = "127.0.0.1:3128";
|
|
11
|
+
/** What a hosted list may hold: Docker's bounds, ports 80 and 443, names and CIDRs together. */
|
|
12
|
+
export declare const HOSTED_ALLOW: AllowCapability;
|
|
13
|
+
/** A network spec as init's --network takes it: "" for none, "open", or "allow:" and the list, normalized. */
|
|
14
|
+
export declare function networkFormOf(network: NetworkSpec): string;
|
|
15
|
+
/** A form, as a label or the policy file holds it, as a network policy: none for no form; anything else in words. */
|
|
16
|
+
export declare function networkOfForm(form: string | undefined): NetworkPolicy;
|
|
17
|
+
/**
|
|
18
|
+
* Why a spec's network is refused by a provider (label) that declares forms, in plain words naming it and the choices;
|
|
19
|
+
* undefined when it is taken. A form the provider does not declare is refused, never widened or narrowed to another.
|
|
20
|
+
*/
|
|
21
|
+
export declare function networkRefusal(label: string, forms: readonly NetworkForm[], network: unknown): string | undefined;
|
|
22
|
+
/** Whether a spec's network goes out through the proxy: open, or a list. */
|
|
23
|
+
export declare const throughProxy: (network: unknown) => boolean;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// A hosted computer's network, as the shared adapter (./provider.ts) makes, records and reads it back. Its programs run
|
|
2
|
+
// in a network of their own whose loopback alone is up (isolation.ts), so "none" holds by itself. "open" and a host list
|
|
3
|
+
// go through one egress proxy per computer that init, still root and in the machine's own network, starts before it
|
|
4
|
+
// leaves it (`computerd init --own-network --network <form>`, daemon/internal/egress): the proxy runs as nobody, listens
|
|
5
|
+
// on a Unix socket only root and the tool user's group reach, and goes to the public internet alone, so the vendor's
|
|
6
|
+
// agent, metadata, the machine's own addresses and every private range stay out of reach; with a list, to its hosts
|
|
7
|
+
// alone, refused before any lookup. Init relays the programs' loopback port 3128 to it and tells them it is their proxy.
|
|
8
|
+
// The machine itself gets the vendor's egress for it. The form is recorded in a label, written to the policy file init
|
|
9
|
+
// leaves beside the socket, and both are read back.
|
|
10
|
+
import { allowOf, MAX_ALLOW } from "../docker/egress.js";
|
|
11
|
+
import { LISTED_PORTS } from "../docker/egress-proxy.js";
|
|
12
|
+
import { COMPUTER_LABEL, DAEMON_IN_COMPUTER } from "../drift.js";
|
|
13
|
+
/** The label a computer whose network is open or a list carries: its form, as init was given it. None carries none. */
|
|
14
|
+
export const NETWORK_LABEL = `${COMPUTER_LABEL}.network`;
|
|
15
|
+
const EGRESS_DIR = `${DAEMON_IN_COMPUTER.slice(0, DAEMON_IN_COMPUTER.lastIndexOf("/"))}/egress`;
|
|
16
|
+
/** Where init's proxy listens, and where it writes the form it serves (daemon/internal/egress/serve.go). */
|
|
17
|
+
export const EGRESS_PROXY_SOCKET = `${EGRESS_DIR}/egress.sock`;
|
|
18
|
+
export const EGRESS_POLICY = `${EGRESS_DIR}/policy`;
|
|
19
|
+
/** The uid and gid init's proxy runs as, nobody (serve.go ProxyUser): no computer's user under open or a list may be it. */
|
|
20
|
+
export const EGRESS_PROXY_USER = 65534;
|
|
21
|
+
/** Init's relay on its programs' own loopback, which carries each connection to the proxy (daemon/internal/egress). */
|
|
22
|
+
export const EGRESS_RELAY = "127.0.0.1:3128"; // key-gate: loopback-rule the computer's own loopback, where init's egress relay listens
|
|
23
|
+
/** What a hosted list may hold: Docker's bounds, ports 80 and 443, names and CIDRs together. */
|
|
24
|
+
export const HOSTED_ALLOW = {
|
|
25
|
+
domains: { max: MAX_ALLOW, ports: [...LISTED_PORTS] },
|
|
26
|
+
cidrs: { max: MAX_ALLOW, ports: [...LISTED_PORTS] },
|
|
27
|
+
mixed: true,
|
|
28
|
+
};
|
|
29
|
+
/** A network spec as init's --network takes it: "" for none, "open", or "allow:" and the list, normalized. */
|
|
30
|
+
export function networkFormOf(network) {
|
|
31
|
+
if (network === "none")
|
|
32
|
+
return "";
|
|
33
|
+
if (network === "open")
|
|
34
|
+
return "open";
|
|
35
|
+
const allow = allowOf(network.allow);
|
|
36
|
+
if ("problem" in allow)
|
|
37
|
+
throw new Error(allow.problem);
|
|
38
|
+
return `allow:${allow.list.join(",")}`;
|
|
39
|
+
}
|
|
40
|
+
/** A form, as a label or the policy file holds it, as a network policy: none for no form; anything else in words. */
|
|
41
|
+
export function networkOfForm(form) {
|
|
42
|
+
if (form === undefined || form === "")
|
|
43
|
+
return "none";
|
|
44
|
+
if (form === "open")
|
|
45
|
+
return "open";
|
|
46
|
+
if (form.startsWith("allow:")) {
|
|
47
|
+
const allow = allowOf(form.slice("allow:".length).split(","));
|
|
48
|
+
if (!("problem" in allow) && `allow:${allow.list.join(",")}` === form)
|
|
49
|
+
return { allow: allow.list };
|
|
50
|
+
}
|
|
51
|
+
return { other: `the network ${JSON.stringify(form.slice(0, 200))}, which this provider never makes` };
|
|
52
|
+
}
|
|
53
|
+
const FORM_WORDS = { none: "none", open: "open", allow: "a list ({ allow: [names or CIDRs] })" };
|
|
54
|
+
/** The forms as a choice in words: "none", "none or open", "none, open or a list (...)". */
|
|
55
|
+
const choices = (forms) => {
|
|
56
|
+
const words = forms.map((form) => FORM_WORDS[form]);
|
|
57
|
+
return words.length <= 1 ? (words[0] ?? "none") : `${words.slice(0, -1).join(", ")} or ${words.at(-1)}`;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Why a spec's network is refused by a provider (label) that declares forms, in plain words naming it and the choices;
|
|
61
|
+
* undefined when it is taken. A form the provider does not declare is refused, never widened or narrowed to another.
|
|
62
|
+
*/
|
|
63
|
+
export function networkRefusal(label, forms, network) {
|
|
64
|
+
if (network === "none")
|
|
65
|
+
return forms.includes("none") ? undefined : `${label} can't run with no network; choose ${choices(forms)}`;
|
|
66
|
+
if (network === "open")
|
|
67
|
+
return forms.includes("open") ? undefined : `${label} can't open the network; choose ${choices(forms)}`;
|
|
68
|
+
if (typeof network === "object" && network !== null && !Array.isArray(network) && "allow" in network) {
|
|
69
|
+
if (!forms.includes("allow"))
|
|
70
|
+
return `${label} can't limit the network to a list; choose ${choices(forms)}`;
|
|
71
|
+
const allow = allowOf(network.allow, `${label}'s allowlist`);
|
|
72
|
+
return "problem" in allow ? allow.problem : undefined;
|
|
73
|
+
}
|
|
74
|
+
return `network is required: ${choices(forms)}`;
|
|
75
|
+
}
|
|
76
|
+
/** Whether a spec's network goes out through the proxy: open, or a list. */
|
|
77
|
+
export const throughProxy = (network) => network === "open" || (typeof network === "object" && network !== null && "allow" in network);
|
package/dist/hosted/process.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export declare const CALL_SLACK_MS = 5000;
|
|
|
7
7
|
export declare const seconds: (ms: number) => string;
|
|
8
8
|
/** An error in words, the vendor's name kept, cut to one line of 300 characters. */
|
|
9
9
|
export declare const words: (error: unknown) => string;
|
|
10
|
+
/** text with every secret in it written [redacted], the longest first; an empty or missing secret is skipped. */
|
|
11
|
+
export declare const redact: (text: string, secrets: readonly (string | undefined)[]) => string;
|
|
10
12
|
/** A pause that ends early when signal aborts; never rejects. */
|
|
11
13
|
export declare const pause: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
12
14
|
/** A signal that aborts with the caller's, or once ms pass. */
|
|
@@ -43,18 +45,24 @@ export interface RunResult {
|
|
|
43
45
|
stdout: string;
|
|
44
46
|
stderr: string;
|
|
45
47
|
}
|
|
48
|
+
export declare const OUTPUT_MAX: number;
|
|
46
49
|
/**
|
|
47
|
-
* argv run in the machine as root through exec, stdin (when given
|
|
48
|
-
* ms and the caller's signal; a process past them is killed, and the kill
|
|
49
|
-
* A non-zero exit is a result, not an error.
|
|
50
|
+
* argv run in the machine as root through exec, stdin (when given: one write per piece, each whole UTF-8 text) written
|
|
51
|
+
* and ended, waited for until it ends, within ms and the caller's signal; a process past them is killed, and the kill
|
|
52
|
+
* waited for at most ms (and CALL_SLACK_MS). A non-zero exit is a result, not an error.
|
|
50
53
|
*/
|
|
51
54
|
export declare function runToExit(host: MachineHost, id: string, argv: readonly string[], { stdin, ms, signal, what }: {
|
|
52
|
-
stdin?: Uint8Array
|
|
55
|
+
stdin?: Iterable<Uint8Array>;
|
|
53
56
|
ms: number;
|
|
54
57
|
signal?: AbortSignal;
|
|
55
58
|
what: string;
|
|
56
59
|
}): Promise<Result<RunResult>>;
|
|
57
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* The default upload, for a vendor with no file API: the bytes as base64 text through exec's stdin, in pieces, so a
|
|
62
|
+
* vendor whose stdin takes one request at a time (E2B's sendStdin) is never handed a whole binary, and exec carries text
|
|
63
|
+
* alone. root decodes it into the file (`base64 -d`, which coreutils and busybox both have). head reads the text's length
|
|
64
|
+
* and no more, so the upload never waits for an end of stdin a vendor may not give (hosted/framed-exec.ts).
|
|
65
|
+
*/
|
|
58
66
|
export declare function uploadThroughExec(host: MachineHost, id: string, path: string, bytes: Uint8Array, ms: number, signal?: AbortSignal): Promise<Result<void>>;
|
|
59
67
|
/**
|
|
60
68
|
* The root channel into a machine (for the shared Archil steps): argv as root through exec, stdin (one line, then
|
package/dist/hosted/process.js
CHANGED
|
@@ -14,6 +14,11 @@ export const words = (error) => {
|
|
|
14
14
|
const message = error instanceof Error ? error.message : String(error);
|
|
15
15
|
return `${typeof name === "string" && name !== "Error" ? `${name}: ` : ""}${message}`.replace(/\s+/g, " ").slice(0, 300);
|
|
16
16
|
};
|
|
17
|
+
/** text with every secret in it written [redacted], the longest first; an empty or missing secret is skipped. */
|
|
18
|
+
export const redact = (text, secrets) => secrets
|
|
19
|
+
.filter((secret) => !!secret)
|
|
20
|
+
.sort((a, b) => b.length - a.length)
|
|
21
|
+
.reduce((said, secret) => said.replaceAll(secret, "[redacted]"), text);
|
|
17
22
|
/** A pause that ends early when signal aborts; never rejects. */
|
|
18
23
|
export const pause = (ms, signal) => new Promise((done) => {
|
|
19
24
|
const timer = setTimeout(finish, ms);
|
|
@@ -134,11 +139,11 @@ async function drain(stream, max) {
|
|
|
134
139
|
}
|
|
135
140
|
return kept;
|
|
136
141
|
}
|
|
137
|
-
const OUTPUT_MAX = 64 * 1024;
|
|
142
|
+
export const OUTPUT_MAX = 64 * 1024;
|
|
138
143
|
/**
|
|
139
|
-
* argv run in the machine as root through exec, stdin (when given
|
|
140
|
-
* ms and the caller's signal; a process past them is killed, and the kill
|
|
141
|
-
* A non-zero exit is a result, not an error.
|
|
144
|
+
* argv run in the machine as root through exec, stdin (when given: one write per piece, each whole UTF-8 text) written
|
|
145
|
+
* and ended, waited for until it ends, within ms and the caller's signal; a process past them is killed, and the kill
|
|
146
|
+
* waited for at most ms (and CALL_SLACK_MS). A non-zero exit is a result, not an error.
|
|
142
147
|
*/
|
|
143
148
|
export async function runToExit(host, id, argv, { stdin, ms, signal, what }) {
|
|
144
149
|
const fail = failFor(host.descriptor.id);
|
|
@@ -149,15 +154,14 @@ export async function runToExit(host, id, argv, { stdin, ms, signal, what }) {
|
|
|
149
154
|
const out = drain(proc.stdout, OUTPUT_MAX);
|
|
150
155
|
const err = drain(proc.stderr, OUTPUT_MAX);
|
|
151
156
|
const ran = (async () => {
|
|
152
|
-
//
|
|
153
|
-
// with none to give, stdin ends at once, so the process reads end of file (one that ended already has no stdin). Not
|
|
157
|
+
// With none to give, stdin ends at once, so the process reads end of file (one that ended already has no stdin). Not
|
|
154
158
|
// awaited: a vendor's close that stalls (E2B's closeStdin is a request of its own) never holds up a command that
|
|
155
159
|
// reads no input.
|
|
156
160
|
if (stdin === undefined)
|
|
157
161
|
Promise.resolve().then(() => proc.end()).catch(() => { });
|
|
158
162
|
else {
|
|
159
|
-
for (
|
|
160
|
-
await proc.write(
|
|
163
|
+
for (const piece of stdin)
|
|
164
|
+
await proc.write(piece);
|
|
161
165
|
await proc.end();
|
|
162
166
|
}
|
|
163
167
|
const exitCode = await proc.wait();
|
|
@@ -173,10 +177,29 @@ export async function runToExit(host, id, argv, { stdin, ms, signal, what }) {
|
|
|
173
177
|
}
|
|
174
178
|
return result;
|
|
175
179
|
}
|
|
176
|
-
|
|
177
|
-
|
|
180
|
+
/** A piece of the upload: 192 KiB, which base64 writes as 256 KiB of text, padded at the file's end alone. */
|
|
181
|
+
const UPLOAD_PIECE = 192 * 1024;
|
|
182
|
+
/** The bytes as base64 text, a piece at a time: no more of it in memory at once than one piece. */
|
|
183
|
+
function* base64Pieces(bytes) {
|
|
184
|
+
for (let at = 0; at < bytes.length; at += UPLOAD_PIECE) {
|
|
185
|
+
const piece = Buffer.from(bytes.buffer, bytes.byteOffset + at, Math.min(UPLOAD_PIECE, bytes.length - at));
|
|
186
|
+
yield Buffer.from(piece.toString("base64"), "latin1");
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* The default upload, for a vendor with no file API: the bytes as base64 text through exec's stdin, in pieces, so a
|
|
191
|
+
* vendor whose stdin takes one request at a time (E2B's sendStdin) is never handed a whole binary, and exec carries text
|
|
192
|
+
* alone. root decodes it into the file (`base64 -d`, which coreutils and busybox both have). head reads the text's length
|
|
193
|
+
* and no more, so the upload never waits for an end of stdin a vendor may not give (hosted/framed-exec.ts).
|
|
194
|
+
*/
|
|
178
195
|
export async function uploadThroughExec(host, id, path, bytes, ms, signal) {
|
|
179
|
-
const
|
|
196
|
+
const length = 4 * Math.ceil(bytes.length / 3);
|
|
197
|
+
const ran = await runToExit(host, id, ["sh", "-c", 'umask 077 && head -c "$2" | base64 -d > "$1"', "sh", path, String(length)], {
|
|
198
|
+
stdin: base64Pieces(bytes),
|
|
199
|
+
ms,
|
|
200
|
+
...(signal ? { signal } : {}),
|
|
201
|
+
what: `the upload to ${path}`,
|
|
202
|
+
});
|
|
180
203
|
if (!ran.ok)
|
|
181
204
|
return ran;
|
|
182
205
|
return ran.value.exitCode === 0 ? ok(undefined) : failFor(host.descriptor.id)("vendor", `the upload to ${path} exited with ${ran.value.exitCode}: ${`${ran.value.stdout} ${ran.value.stderr}`.trim().slice(0, 300)}`);
|
|
@@ -189,7 +212,7 @@ export async function uploadThroughExec(host, id, path, bytes, ms, signal) {
|
|
|
189
212
|
export function rootOf(host, id, name) {
|
|
190
213
|
return {
|
|
191
214
|
run: async (argv, { stdin, timeoutMs, signal }) => {
|
|
192
|
-
const ran = await runToExit(host, id, argv, { ...(stdin === undefined ? {} : { stdin: new Uint8Array(Buffer.from(stdin, "utf8")) }), ms: timeoutMs, ...(signal ? { signal } : {}), what: `root's ${argv[0] === undefined ? "command" : argv[0].split("/").pop()} in ${name}` });
|
|
215
|
+
const ran = await runToExit(host, id, argv, { ...(stdin === undefined ? {} : { stdin: [new Uint8Array(Buffer.from(stdin, "utf8"))] }), ms: timeoutMs, ...(signal ? { signal } : {}), what: `root's ${argv[0] === undefined ? "command" : argv[0].split("/").pop()} in ${name}` });
|
|
193
216
|
return ran.ok ? ok({ exitCode: ran.value.exitCode, output: `${ran.value.stdout}${ran.value.stderr}` }) : ran;
|
|
194
217
|
},
|
|
195
218
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type DesktopOptions } from "../desktop.js";
|
|
2
|
-
import type
|
|
2
|
+
import { type Machine, type MachineHost } from "../host.js";
|
|
3
3
|
import { type ProviderNote } from "../mount-archil.js";
|
|
4
4
|
import { type AttachedComputer, type AttachContext, type CallContext, type ComputerCapabilities, type ComputerConnection, type ComputerInfo, type ComputerProvider, type ComputerRef, type ComputerSpec, type CreateContext, type CreatedComputer, type NetworkPolicy, type NetworkSpec, type Refusal, type ReleaseContext, type ReleaseHow } from "../provider.js";
|
|
5
5
|
import { type Result } from "../result.js";
|
|
@@ -22,7 +22,10 @@ export interface HostedTimeouts {
|
|
|
22
22
|
listMs: number;
|
|
23
23
|
/** From a delete to get answering none for the machine. */
|
|
24
24
|
goneMs: number;
|
|
25
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* The first pause between two reads while release waits; the pauses double up to 5 s. The longest pause between two
|
|
27
|
+
* listings while create waits for the new computer to show: those start at 150 ms and double up to it.
|
|
28
|
+
*/
|
|
26
29
|
pollMs: number;
|
|
27
30
|
/** How long create waits for the listing to show the new computer. */
|
|
28
31
|
listedMs: number;
|
|
@@ -68,6 +71,8 @@ export declare const NAME_LABEL = "agentrun.computer.name";
|
|
|
68
71
|
export declare const IMAGE_LABEL = "agentrun.computer.image";
|
|
69
72
|
/** The most extend may move the deadline to: create's time plus the cap, by this machine's clock, as init was given. */
|
|
70
73
|
export declare const MAX_LABEL = "agentrun.computer.max-deadline";
|
|
74
|
+
/** A GPU computer's GPUs, type:count: a retry and attach read them here, so no vendor need read them back. */
|
|
75
|
+
export declare const GPU_LABEL = "agentrun.computer.gpu";
|
|
71
76
|
/** The adapter's timeouts, the caller's over its defaults: what a host reads for its own requestMs or pollMs. */
|
|
72
77
|
export declare const timeoutsOf: (timeouts?: Partial<HostedTimeouts>) => HostedTimeouts;
|
|
73
78
|
/** An ISO time a label holds, or undefined when it is missing or not the ISO time create writes. */
|
|
@@ -91,7 +96,7 @@ export declare class HostedProvider implements ComputerProvider {
|
|
|
91
96
|
readonly host: MachineHost;
|
|
92
97
|
readonly extend?: Extend;
|
|
93
98
|
constructor(host: MachineHost, options: HostedOptions);
|
|
94
|
-
/** The computer's facts, from the host's and the adapter's options alone. */
|
|
99
|
+
/** The computer's facts, from the descriptor, the host's facts and the adapter's options alone. */
|
|
95
100
|
capabilities(): ComputerCapabilities;
|
|
96
101
|
check(spec: ComputerSpec): Refusal[];
|
|
97
102
|
/**
|
|
@@ -119,11 +124,11 @@ export declare class HostedProvider implements ComputerProvider {
|
|
|
119
124
|
}>>;
|
|
120
125
|
/**
|
|
121
126
|
* Every computer this provider made that carries all of these labels, running or stopped: the listing finds them, and
|
|
122
|
-
* a get of each reads its state, labels and end (foundBy). Its network is
|
|
123
|
-
* it from inside.
|
|
127
|
+
* a get of each reads its state, labels and end (foundBy). Its network is the one its label records, as create made
|
|
128
|
+
* it (none without one); attach and network() read it from inside.
|
|
124
129
|
*/
|
|
125
130
|
list(labels: Record<string, string>, { signal }?: CallContext): Promise<Result<ComputerInfo[]>>;
|
|
126
|
-
/** The probe
|
|
131
|
+
/** The probe and the proxy's policy read the network back from inside. A change is refused: it is fixed at create. */
|
|
127
132
|
network(ref: ComputerRef, policy?: NetworkSpec, { signal }?: CallContext): Promise<Result<NetworkPolicy>>;
|
|
128
133
|
/**
|
|
129
134
|
* delete reads the machine back to check it is this provider's, then deletes it, both never signalled, so a release
|
|
@@ -139,13 +144,15 @@ export declare class HostedProvider implements ComputerProvider {
|
|
|
139
144
|
}
|
|
140
145
|
/**
|
|
141
146
|
* The host's listing by labels, bounded by ms: only the machines that carry every one of them, since a vendor's listing
|
|
142
|
-
* may answer more (MachineHost.list).
|
|
147
|
+
* may answer more (MachineHost.list). A host that keeps labels in the machine lists none: its machines of another name
|
|
148
|
+
* are left out, and the rest kept for foundBy to read.
|
|
143
149
|
*/
|
|
144
150
|
export declare function listedBy(host: MachineHost, what: string, labels: Record<string, string>, ms: number, signal?: AbortSignal): Promise<Result<Machine[]>>;
|
|
145
151
|
/**
|
|
146
152
|
* The listing finds, get answers (MachineHost.list): the machines the host's listing by labels names, each read now by
|
|
147
|
-
* readMachine, within requestMs
|
|
148
|
-
* not every label
|
|
153
|
+
* readMachine, within requestMs, and its label file where the host keeps labels in the machine. One the vendor no longer
|
|
154
|
+
* has (not found) is dropped, and so is one whose get carries not every label, but a machine of the name asked for whose
|
|
155
|
+
* labels are not written yet. A read that fails otherwise fails the whole.
|
|
149
156
|
*/
|
|
150
157
|
export declare function foundBy(host: MachineHost, what: string, labels: Record<string, string>, { listMs, requestMs }: Pick<HostedTimeouts, "listMs" | "requestMs">, signal?: AbortSignal): Promise<Result<Machine[]>>;
|
|
151
158
|
/**
|