@parcha/agentrun-computer 0.1.0-beta.33 → 0.1.0-beta.35
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 +308 -36
- package/dist/browser.d.ts +13 -14
- package/dist/browser.js +22 -17
- package/dist/browserbase.d.ts +3 -3
- package/dist/browserbase.js +16 -11
- package/dist/child.d.ts +2 -0
- package/dist/child.js +13 -2
- package/dist/chrome.d.ts +73 -0
- package/dist/chrome.js +224 -0
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/conformance/browserbase.js +1 -1
- package/dist/conformance/cases/gpu.d.ts +2 -0
- package/dist/conformance/cases/gpu.js +108 -0
- package/dist/conformance/cases/health.js +83 -3
- package/dist/conformance/cases/index.js +2 -0
- package/dist/conformance/cases/mount.d.ts +8 -1
- package/dist/conformance/cases/mount.js +4 -3
- package/dist/conformance/cases/provider.js +92 -3
- package/dist/conformance/cli.js +46 -7
- package/dist/conformance/daytona.js +2 -1
- package/dist/conformance/e2b.js +2 -1
- package/dist/conformance/fixture.js +24 -2
- package/dist/conformance/kernel.js +1 -1
- package/dist/conformance/kind.js +2 -1
- package/dist/conformance/local-chrome.d.ts +30 -0
- package/dist/conformance/local-chrome.js +36 -0
- package/dist/conformance/orgo.d.ts +11 -5
- package/dist/conformance/orgo.js +37 -8
- package/dist/conformance/phone-harness.js +2 -1
- package/dist/conformance/report.js +13 -7
- package/dist/conformance/runner.js +68 -18
- package/dist/conformance/types.d.ts +78 -18
- package/dist/conformance/types.js +10 -0
- package/dist/conformance/windows-fixture.d.ts +1 -0
- package/dist/conformance/windows-fixture.js +37 -0
- package/dist/daytona.d.ts +4 -6
- package/dist/daytona.js +97 -52
- package/dist/descriptor.d.ts +94 -0
- package/dist/descriptor.js +81 -0
- package/dist/descriptors/browserbase.d.ts +24 -0
- package/dist/descriptors/browserbase.js +18 -0
- package/dist/descriptors/daytona.d.ts +62 -0
- package/dist/descriptors/daytona.js +49 -0
- package/dist/descriptors/docker.d.ts +12 -0
- package/dist/descriptors/docker.js +17 -0
- package/dist/descriptors/e2b.d.ts +22 -0
- package/dist/descriptors/e2b.js +19 -0
- package/dist/descriptors/index.d.ts +229 -0
- package/dist/descriptors/index.js +19 -0
- package/dist/descriptors/kernel.d.ts +20 -0
- package/dist/descriptors/kernel.js +15 -0
- package/dist/descriptors/local-chrome.d.ts +17 -0
- package/dist/descriptors/local-chrome.js +21 -0
- package/dist/descriptors/modal.d.ts +50 -0
- package/dist/descriptors/modal.js +38 -0
- package/dist/descriptors/orgo.d.ts +88 -0
- package/dist/descriptors/orgo.js +44 -0
- package/dist/descriptors/phone-harness.d.ts +28 -0
- package/dist/descriptors/phone-harness.js +20 -0
- package/dist/descriptors/shared.d.ts +7 -0
- package/dist/descriptors/shared.js +6 -0
- package/dist/desktop.d.ts +4 -4
- package/dist/desktop.js +4 -4
- package/dist/docker/egress.d.ts +1 -1
- package/dist/docker/image.js +17 -15
- package/dist/docker/inspect.d.ts +147 -0
- package/dist/docker/inspect.js +335 -0
- package/dist/docker.d.ts +6 -4
- package/dist/docker.js +53 -41
- package/dist/drift.d.ts +6 -146
- package/dist/drift.js +14 -334
- package/dist/e2b.d.ts +2 -6
- package/dist/e2b.js +19 -22
- package/dist/index.d.ts +9 -10
- package/dist/index.js +14 -10
- package/dist/isolation.d.ts +0 -2
- package/dist/isolation.js +2 -18
- package/dist/janitor.d.ts +18 -1
- package/dist/janitor.js +67 -19
- package/dist/kernel.d.ts +3 -3
- package/dist/kernel.js +19 -14
- package/dist/kinds.d.ts +56 -30
- package/dist/kinds.js +19 -97
- package/dist/labels.d.ts +18 -0
- package/dist/labels.js +65 -2
- package/dist/local-chrome.d.ts +86 -0
- package/dist/local-chrome.js +475 -0
- package/dist/local-supervisor.d.ts +51 -0
- package/dist/local-supervisor.js +221 -0
- package/dist/modal.d.ts +15 -7
- package/dist/modal.js +83 -39
- package/dist/mount-archil.js +4 -4
- package/dist/orgo-channel.js +16 -13
- package/dist/orgo-desktop.d.ts +153 -0
- package/dist/orgo-desktop.js +1614 -0
- package/dist/orgo-names.d.ts +52 -0
- package/dist/orgo-names.js +84 -0
- package/dist/orgo.d.ts +18 -13
- package/dist/orgo.js +54 -128
- package/dist/phone-harness.d.ts +4 -8
- package/dist/phone-harness.js +48 -46
- package/dist/protocol.d.ts +20 -0
- package/dist/protocol.js +9 -0
- package/dist/provider.d.ts +151 -10
- package/dist/provider.js +70 -0
- package/dist/providers.d.ts +22 -17
- package/dist/providers.js +14 -16
- package/dist/result.d.ts +11 -1
- package/dist/result.js +11 -0
- package/dist/test-connection.js +2 -2
- package/package.json +42 -2
package/dist/drift.js
CHANGED
|
@@ -1,169 +1,22 @@
|
|
|
1
|
-
// The drift
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import { engineOf, subpathOf } from "./docker/volume.js";
|
|
6
|
-
import { WORKSPACE } from "./mount.js";
|
|
1
|
+
// The drift checks every provider shares: the daemon's hello against what the provider declares, and the report of
|
|
2
|
+
// computerd probe from inside a computer. Pure: no vendor call. Each mismatch is one sentence; none is an empty list.
|
|
3
|
+
// Docker's own read-back (docker info, docker inspect) is docker/inspect.ts's.
|
|
4
|
+
import { NETWORK_FENCES, PROTOCOL_VERSION } from "./protocol.js";
|
|
7
5
|
/** Where the daemon is mounted in each computer, read-only. */
|
|
8
6
|
export const DAEMON_IN_COMPUTER = "/opt/agentrun/computerd";
|
|
9
|
-
/** With the Docker provider's volume option, where the daemon's staged directory is mounted read-only: its computerd is
|
|
10
|
-
* DAEMON_IN_COMPUTER (src/docker/stage.ts). */
|
|
11
|
-
export const DAEMON_DIR_IN_COMPUTER = "/opt/agentrun";
|
|
12
7
|
export const COMPUTER_LABEL = "agentrun.computer";
|
|
13
8
|
export const DEADLINE_LABEL = "agentrun.computer.deadline";
|
|
14
9
|
/** Serve's box sizes, when the spec names none. */
|
|
15
10
|
export const DEFAULT_CPUS = 2;
|
|
16
11
|
export const DEFAULT_MEMORY_MB = 4096;
|
|
17
12
|
export const DEFAULT_PIDS = 1024;
|
|
18
|
-
/** CPUs are a CFS quota of each 100 ms, as serve gives them: Docker refuses a --cpus above its own CPU count. */
|
|
19
|
-
export const CPU_PERIOD_US = 100_000;
|
|
20
13
|
/** The computer's home and default workdir: a tmpfs its user owns. The run's folder, when bound, is at WORKSPACE. */
|
|
21
14
|
export const WORK = "/work";
|
|
22
15
|
/** Where init's socket lives (the daemon's DefaultSocket's directory): a tmpfs the computer's user owns, mode 0700. */
|
|
23
16
|
export const SOCKET_DIR = "/run/agentrun";
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
* computer's memory, so /work holds half of it: a full /work is ENOSPC before the memory limit could OOM-kill a
|
|
27
|
-
* process. /run/agentrun holds only init's socket.
|
|
28
|
-
*/
|
|
29
|
-
export function tmpfsOf(user, memoryMb) {
|
|
30
|
-
const [uid, gid] = user.split(":");
|
|
31
|
-
return {
|
|
32
|
-
[WORK]: `rw,nosuid,nodev,exec,uid=${uid},gid=${gid},mode=0700,size=${Math.floor(memoryMb / 2)}m`,
|
|
33
|
-
[SOCKET_DIR]: `rw,noexec,nosuid,nodev,uid=${uid},gid=${gid},mode=0700,size=1m`,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
/** docker info names the kernel's architecture; hello names Go's. */
|
|
37
|
-
const GO_ARCH = { x86_64: "amd64", aarch64: "arm64" };
|
|
38
|
-
/**
|
|
39
|
-
* The host's enforcement, from docker info. A computer's sizes are cgroup limits, so a host that does not enforce one
|
|
40
|
-
* makes it configuration only; seccomp is required, since a computer's only syscall filter is Docker's default
|
|
41
|
-
* profile. AppArmor and SELinux are read, not required: a host has the one its distribution ships or neither, and a
|
|
42
|
-
* computer must then carry the profile or label Docker gives every container (the drift check).
|
|
43
|
-
*/
|
|
44
|
-
export function hostOf(info) {
|
|
45
|
-
const problems = [];
|
|
46
|
-
const lacks = (flag, what, so) => {
|
|
47
|
-
if (flag !== true)
|
|
48
|
-
problems.push(`this Docker host does not enforce ${what}, so ${so}`);
|
|
49
|
-
};
|
|
50
|
-
lacks(info?.MemoryLimit, "memory limits", "a computer's memory size is only configuration");
|
|
51
|
-
lacks(info?.SwapLimit, "swap limits", "a computer could swap past its memory size");
|
|
52
|
-
lacks(info?.PidsLimit, "pids limits", "a computer's pids limit is only configuration");
|
|
53
|
-
lacks(info?.CPUCfsQuota, "CPU quotas", "a computer's cpus are only configuration");
|
|
54
|
-
lacks(info?.CPUCfsPeriod, "CPU periods", "a computer's cpus are only configuration");
|
|
55
|
-
const options = Array.isArray(info?.SecurityOptions) ? info.SecurityOptions.filter((option) => typeof option === "string") : [];
|
|
56
|
-
const named = (name) => options.find((option) => option.split(",").includes(`name=${name}`));
|
|
57
|
-
const seccomp = named("seccomp");
|
|
58
|
-
if (seccomp === undefined)
|
|
59
|
-
problems.push("this Docker host has no seccomp, so a computer could make any system call");
|
|
60
|
-
else if (seccomp.split(",").includes("profile=unconfined")) {
|
|
61
|
-
problems.push("this Docker host's default seccomp profile is unconfined, so a computer could make any system call");
|
|
62
|
-
}
|
|
63
|
-
const machine = typeof info?.Architecture === "string" ? info.Architecture : "";
|
|
64
|
-
const remap = named("userns") !== undefined ? "userns" : named("rootless") !== undefined ? "rootless" : undefined;
|
|
65
|
-
const engine = engineOf(info?.ServerVersion);
|
|
66
|
-
return { arch: GO_ARCH[machine] ?? machine, apparmor: named("apparmor") !== undefined, selinux: named("selinux") !== undefined, problems, ...(remap ? { remap } : {}), ...(engine === undefined ? {} : { engine }) };
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* How create mounts a path of this host at `target`: a bind of it, or, with the provider's volume option, the volume's
|
|
70
|
-
* subpath, as HostConfig.Mounts records it (Docker keeps `volume-nocopy` and the subpath under VolumeOptions). Undefined
|
|
71
|
-
* for a path outside the volume, which create never mounts.
|
|
72
|
-
*/
|
|
73
|
-
export function mountAsked(path, target, readonly, volume) {
|
|
74
|
-
if (volume === undefined)
|
|
75
|
-
return { Type: "bind", Source: path, Target: target, ...(readonly ? { ReadOnly: true } : {}) };
|
|
76
|
-
const subpath = subpathOf(volume, path);
|
|
77
|
-
if (subpath === undefined)
|
|
78
|
-
return undefined;
|
|
79
|
-
return { Type: "volume", Source: volume.name, Target: target, ...(readonly ? { ReadOnly: true } : {}), VolumeOptions: { NoCopy: true, Subpath: subpath } };
|
|
80
|
-
}
|
|
81
|
-
const show = (value) => (value === undefined ? "nothing" : JSON.stringify(value));
|
|
17
|
+
/** A value as a drift sentence shows it: JSON, or "nothing". */
|
|
18
|
+
export const show = (value) => (value === undefined ? "nothing" : JSON.stringify(value));
|
|
82
19
|
const text = (value) => (typeof value === "string" ? value : show(value));
|
|
83
|
-
const sameList = (a, b) => Array.isArray(a) && a.length === b.length && a.every((item, i) => item === b[i]);
|
|
84
|
-
/** Docker's default for a field it reports: nothing, an empty string, list or map, zero or false. A map with any key,
|
|
85
|
-
* even to an empty value (a VOLUME's {}), is not. */
|
|
86
|
-
const blank = (value) => value === undefined || value === null || value === "" || value === 0 || value === false || (typeof value === "object" && Object.keys(value).length === 0);
|
|
87
|
-
/** Docker's masked and read-only paths in every release since 20.10; a newer one masks more. */
|
|
88
|
-
const MASKED_PATHS = ["/proc/acpi", "/proc/asound", "/proc/kcore", "/proc/keys", "/proc/latency_stats", "/proc/sched_debug", "/proc/scsi", "/proc/timer_list", "/proc/timer_stats", "/sys/firmware"];
|
|
89
|
-
const READONLY_PATHS = ["/proc/bus", "/proc/fs", "/proc/irq", "/proc/sys", "/proc/sysrq-trigger"];
|
|
90
|
-
const holds = (value, paths) => Array.isArray(value) && paths.every((path) => value.includes(path));
|
|
91
|
-
/**
|
|
92
|
-
* The closed check of HostConfig. A field named here is checked in drift() for what create asked for, is checked
|
|
93
|
-
* here for a default other than blank, or is irrelevant (its value widens nothing the box bounds). Every other field,
|
|
94
|
-
* one Docker adds later included, must be blank.
|
|
95
|
-
*/
|
|
96
|
-
const HOST_ASKED = new Set(["NetworkMode", "CapDrop", "CapAdd", "Privileged", "SecurityOpt", "PidsLimit", "Memory", "MemorySwap", "CpuPeriod", "CpuQuota", "Tmpfs", "Mounts", "IpcMode", "CgroupnsMode", "MaskedPaths", "ReadonlyPaths", "Runtime"]);
|
|
97
|
-
const HOST_DEFAULTS = {
|
|
98
|
-
RestartPolicy: [
|
|
99
|
-
(v) => {
|
|
100
|
-
const { Name, MaximumRetryCount, ...rest } = (v ?? {});
|
|
101
|
-
return (blank(Name) || Name === "no") && blank(MaximumRetryCount) && Object.values(rest).every(blank);
|
|
102
|
-
},
|
|
103
|
-
'no restart ("no")',
|
|
104
|
-
],
|
|
105
|
-
Isolation: [(v) => blank(v) || v === "default", "Docker's default"],
|
|
106
|
-
MemorySwappiness: [(v) => blank(v) || v === -1, "the kernel's (null)"],
|
|
107
|
-
};
|
|
108
|
-
/** Values the host or Docker chooses that a computer cannot widen itself by: logs, the console, /dev/shm (charged to the
|
|
109
|
-
* computer's memory), rlimits (inside the cgroup's limits) and the file create's cid would go to. */
|
|
110
|
-
const HOST_IRRELEVANT = new Set(["ContainerIDFile", "LogConfig", "ConsoleSize", "ShmSize", "Ulimits"]);
|
|
111
|
-
/** The closed check of Config, the same way: the image's own settings that run only inside the computer are irrelevant. */
|
|
112
|
-
const CONFIG_ASKED = new Set(["User", "Image", "WorkingDir", "Env", "Entrypoint", "Cmd", "Labels"]);
|
|
113
|
-
const CONFIG_IRRELEVANT = new Set([
|
|
114
|
-
"Hostname", "Domainname", "AttachStdin", "AttachStdout", "AttachStderr", "Tty", "OpenStdin", "StdinOnce", "ExposedPorts", "Healthcheck",
|
|
115
|
-
"ArgsEscaped", "OnBuild", "StopSignal", "StopTimeout", "Shell", "MacAddress", "NetworkDisabled",
|
|
116
|
-
]);
|
|
117
|
-
/** A mount's options as a set, so their order is no drift. */
|
|
118
|
-
const optionSet = (options) => (typeof options === "string" ? options.split(",").sort().join(",") : undefined);
|
|
119
|
-
/** Whether a computer's inspect shows any part of an allowlist: the egress volume at its path, or init's relay. */
|
|
120
|
-
export function egressShaped(inspected) {
|
|
121
|
-
const cmd = inspected?.Config?.Cmd;
|
|
122
|
-
return (inspected?.Mounts ?? []).some((mount) => mount.Destination === EGRESS_MOUNT) || (Array.isArray(cmd) && cmd.includes(RELAY_FLAG));
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* The network a computer is on, read back from inspect: `none` is network mode none on no network but Docker's own
|
|
126
|
-
* `none`, `open` is the default bridge alone. An allowlist is network mode none with the computer's egress volume
|
|
127
|
-
* mounted read-only at EGRESS_MOUNT and init relaying to its socket, and the list read back from `proxy`, the
|
|
128
|
-
* computer's proxy container's inspect (egressOf: none when it is gone), which must refuse each of `local`, the Docker
|
|
129
|
-
* host's own addresses. Anything else is reported in words, never as a policy it might widen to.
|
|
130
|
-
*/
|
|
131
|
-
export function networkOf(inspected, proxy, code, local) {
|
|
132
|
-
const mode = inspected?.HostConfig?.NetworkMode;
|
|
133
|
-
const networks = Object.keys(inspected?.NetworkSettings?.Networks ?? {}).sort();
|
|
134
|
-
const none = mode === "none" && networks.every((name) => name === "none");
|
|
135
|
-
const where = `network mode ${mode ?? "unknown"} on networks ${networks.join(", ") || "none"}`;
|
|
136
|
-
if (!egressShaped(inspected)) {
|
|
137
|
-
if (none)
|
|
138
|
-
return "none";
|
|
139
|
-
if (mode === "bridge" && sameList(networks, ["bridge"]))
|
|
140
|
-
return "open";
|
|
141
|
-
return { other: where };
|
|
142
|
-
}
|
|
143
|
-
if (!none)
|
|
144
|
-
return { other: `${where}, with an egress volume or relay, which this provider never makes` };
|
|
145
|
-
const name = (inspected?.Name ?? "").replace(/^\//, "");
|
|
146
|
-
const at = (inspected?.Mounts ?? []).filter((mount) => mount.Destination === EGRESS_MOUNT);
|
|
147
|
-
const cmd = inspected?.Config?.Cmd;
|
|
148
|
-
const relay = Array.isArray(cmd) ? cmd.indexOf(RELAY_FLAG) : -1;
|
|
149
|
-
if (at.length === 0)
|
|
150
|
-
return { other: `init's relay points at ${show(Array.isArray(cmd) ? cmd[relay + 1] : undefined)} but no egress volume is mounted at ${EGRESS_MOUNT}` };
|
|
151
|
-
if (relay < 0)
|
|
152
|
-
return { other: `an egress volume at ${EGRESS_MOUNT} but no relay in init's command` };
|
|
153
|
-
if (cmd?.[relay + 1] !== EGRESS_SOCKET)
|
|
154
|
-
return { other: `init relays to ${show(cmd?.[relay + 1])}, not ${EGRESS_SOCKET}` };
|
|
155
|
-
const [only] = at;
|
|
156
|
-
if (at.length !== 1 || only?.Type !== "volume" || only.Name !== egressNameOf(name) || only.RW !== false) {
|
|
157
|
-
return { other: `the egress volume at ${EGRESS_MOUNT} is ${at.map(mountWords).join(", ")}, not ${egressNameOf(name)} read-only` };
|
|
158
|
-
}
|
|
159
|
-
return egressOf(proxy, { name, user: inspected?.Config?.User, deadline: inspected?.Config?.Labels?.[DEADLINE_LABEL], running: inspected?.State?.Running === true }, code, local);
|
|
160
|
-
}
|
|
161
|
-
/** Whether a policy read back is the one declared: the same string, or an allowlist with the same entries, normalized. */
|
|
162
|
-
export function samePolicy(declared, read) {
|
|
163
|
-
if (typeof declared === "string" || typeof read === "string")
|
|
164
|
-
return declared === read;
|
|
165
|
-
return "allow" in declared && "allow" in read && sameAllow(declared.allow, read.allow);
|
|
166
|
-
}
|
|
167
20
|
const isAddresses = (value) => Array.isArray(value) && value.every((one) => typeof one === "string");
|
|
168
21
|
const isId = (value) => typeof value === "number" && Number.isSafeInteger(value);
|
|
169
22
|
/**
|
|
@@ -208,33 +61,14 @@ export function probeNetworkDrift(probe) {
|
|
|
208
61
|
export function probeNotes(probe, network) {
|
|
209
62
|
return network === "none" && probe.accepted.length > 0 ? [`network: none; accepted with no answer (no bytes came back): ${probe.accepted.join(", ")}`] : [];
|
|
210
63
|
}
|
|
211
|
-
/** One mount as a person reads it: "a read-write bind of /runs/r1". */
|
|
212
|
-
const mountWords = (mount) => `a ${mount.RW === true ? "read-write" : "read-only"} ${mount.Type ?? "mount"} of ${mount.Source ?? mount.Name ?? "nothing"}`;
|
|
213
|
-
/**
|
|
214
|
-
* What is mounted at /workspace, read back from inspect: a read-write bind is the run's folder; nothing is undefined;
|
|
215
|
-
* anything else (read-only, a volume, two mounts) is reported in words, never as a bind it might be.
|
|
216
|
-
*/
|
|
217
|
-
export function mountOf(inspected, volume) {
|
|
218
|
-
const at = (inspected?.Mounts ?? []).filter((mount) => mount.Destination === WORKSPACE);
|
|
219
|
-
const [only] = at;
|
|
220
|
-
if (only === undefined)
|
|
221
|
-
return undefined;
|
|
222
|
-
if (volume === undefined && at.length === 1 && only.Type === "bind" && only.RW === true && typeof only.Source === "string")
|
|
223
|
-
return { kind: "bind", path: only.Source };
|
|
224
|
-
// With the provider's volume option, the folder is the volume's subpath, read read-write from HostConfig.Mounts, and
|
|
225
|
-
// reported as the path below the root create was given.
|
|
226
|
-
if (volume !== undefined && at.length === 1 && only.Type === "volume" && only.Name === volume.name && only.RW === true) {
|
|
227
|
-
const asked = (inspected?.HostConfig?.Mounts ?? []).filter((mount) => mount.Target === WORKSPACE);
|
|
228
|
-
const subpath = asked[0]?.VolumeOptions?.Subpath;
|
|
229
|
-
if (asked.length === 1 && asked[0]?.Type === "volume" && asked[0].Source === volume.name && typeof subpath === "string" && subpath !== "" && !subpath.split("/").includes("..")) {
|
|
230
|
-
return { kind: "bind", path: join(volume.root, subpath) };
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
return { other: `${at.map(mountWords).join(", ")} at ${WORKSPACE}` };
|
|
234
|
-
}
|
|
235
64
|
/** Every way hello differs from what the provider expects. */
|
|
236
65
|
export function helloDrift(hello, expected) {
|
|
237
66
|
const found = [];
|
|
67
|
+
// Another protocol version is another wire. A hello with none is a daemon from before the protocol was versioned,
|
|
68
|
+
// which the version check below already refuses as another daemon.
|
|
69
|
+
if (hello?.protocol !== undefined && hello.protocol !== PROTOCOL_VERSION) {
|
|
70
|
+
found.push(`hello: the daemon speaks protocol ${text(hello.protocol)}, expected ${PROTOCOL_VERSION}`);
|
|
71
|
+
}
|
|
238
72
|
if (hello?.version !== expected.version)
|
|
239
73
|
found.push(`hello: the daemon reports version ${text(hello?.version)}, expected ${expected.version}`);
|
|
240
74
|
if (hello?.os !== "linux")
|
|
@@ -244,6 +78,9 @@ export function helloDrift(hello, expected) {
|
|
|
244
78
|
}
|
|
245
79
|
if (hello?.kind !== expected.kind)
|
|
246
80
|
found.push(`hello: the daemon reports kind ${text(hello?.kind)}, expected ${expected.kind}`);
|
|
81
|
+
if (expected.fence && !NETWORK_FENCES.includes(hello?.fence)) {
|
|
82
|
+
found.push(`hello: the daemon reports fence ${text(hello?.fence)}: init was started with --own-network, so its programs must be held behind one, ${NETWORK_FENCES.join(" or ")}`);
|
|
83
|
+
}
|
|
247
84
|
const offered = hello?.groups;
|
|
248
85
|
if (!Array.isArray(offered)) {
|
|
249
86
|
found.push(`hello: the daemon reports groups ${show(offered)}, not a list; expected ${expected.groups.join(", ")}`);
|
|
@@ -257,160 +94,3 @@ export function helloDrift(hello, expected) {
|
|
|
257
94
|
found.push(`hello: the daemon offers groups ${extra.map(text).join(", ")}, which the provider does not declare`);
|
|
258
95
|
return found;
|
|
259
96
|
}
|
|
260
|
-
/** Every way a created computer differs from its spec, from inspect and hello. */
|
|
261
|
-
export function drift(spec, inspected, hello, expected) {
|
|
262
|
-
return [...inspectDrift(spec, inspected, expected), ...helloDrift(hello, expected)];
|
|
263
|
-
}
|
|
264
|
-
/** Every way a computer's docker inspect differs from its spec: the fields create asks for, and the closed check. */
|
|
265
|
-
export function inspectDrift(spec, inspected, expected) {
|
|
266
|
-
const found = [];
|
|
267
|
-
const mismatch = (field, declared, actual) => found.push(`${field}: declared ${show(declared)}, read back ${show(actual)}`);
|
|
268
|
-
const host = inspected?.HostConfig ?? {};
|
|
269
|
-
const config = inspected?.Config ?? {};
|
|
270
|
-
const network = networkOf(inspected, expected.proxy, expected.egressCode, expected.hostAddresses);
|
|
271
|
-
if (!samePolicy(spec.network, network))
|
|
272
|
-
found.push(`network: declared ${policyWords(spec.network)}, read back ${policyWords(network)}`);
|
|
273
|
-
const allowed = typeof spec.network === "object" && spec.network !== null && "allow" in spec.network;
|
|
274
|
-
const volume = egressNameOf((inspected?.Name ?? "").replace(/^\//, ""));
|
|
275
|
-
if (!sameList(host.CapDrop, ["ALL"]))
|
|
276
|
-
mismatch("CapDrop", ["ALL"], host.CapDrop);
|
|
277
|
-
if ((host.CapAdd ?? []).length > 0)
|
|
278
|
-
mismatch("CapAdd", [], host.CapAdd);
|
|
279
|
-
if (host.Privileged !== false)
|
|
280
|
-
mismatch("Privileged", false, host.Privileged);
|
|
281
|
-
if (!sameList(host.SecurityOpt, ["no-new-privileges"]))
|
|
282
|
-
mismatch("SecurityOpt", ["no-new-privileges"], host.SecurityOpt);
|
|
283
|
-
if (host.IpcMode !== "private")
|
|
284
|
-
mismatch("IpcMode", "private", host.IpcMode);
|
|
285
|
-
if (host.CgroupnsMode !== "private")
|
|
286
|
-
mismatch("CgroupnsMode", "private", host.CgroupnsMode);
|
|
287
|
-
if (host.Runtime !== "runc")
|
|
288
|
-
mismatch("Runtime", "runc", host.Runtime);
|
|
289
|
-
if (!holds(host.MaskedPaths, MASKED_PATHS))
|
|
290
|
-
found.push(`MaskedPaths: must hold Docker's ${show(MASKED_PATHS)}, read back ${show(host.MaskedPaths)}`);
|
|
291
|
-
if (!holds(host.ReadonlyPaths, READONLY_PATHS))
|
|
292
|
-
found.push(`ReadonlyPaths: must hold Docker's ${show(READONLY_PATHS)}, read back ${show(host.ReadonlyPaths)}`);
|
|
293
|
-
const pids = spec.pids ?? DEFAULT_PIDS;
|
|
294
|
-
if (host.PidsLimit !== pids)
|
|
295
|
-
mismatch("PidsLimit", pids, host.PidsLimit);
|
|
296
|
-
const memoryMb = spec.memoryMb ?? DEFAULT_MEMORY_MB;
|
|
297
|
-
const bytes = memoryMb * 1024 * 1024;
|
|
298
|
-
if (host.Memory !== bytes)
|
|
299
|
-
mismatch("Memory", bytes, host.Memory);
|
|
300
|
-
if (host.MemorySwap !== bytes)
|
|
301
|
-
mismatch("MemorySwap", bytes, host.MemorySwap);
|
|
302
|
-
if (host.CpuPeriod !== CPU_PERIOD_US)
|
|
303
|
-
mismatch("CpuPeriod", CPU_PERIOD_US, host.CpuPeriod);
|
|
304
|
-
const quota = Math.round((spec.cpus ?? DEFAULT_CPUS) * CPU_PERIOD_US);
|
|
305
|
-
if (host.CpuQuota !== quota)
|
|
306
|
-
mismatch("CpuQuota", quota, host.CpuQuota);
|
|
307
|
-
const tmpfs = host.Tmpfs ?? {};
|
|
308
|
-
const tmpfsAsked = tmpfsOf(expected.user, memoryMb);
|
|
309
|
-
for (const [path, options] of Object.entries(tmpfsAsked)) {
|
|
310
|
-
if (optionSet(tmpfs[path]) !== optionSet(options))
|
|
311
|
-
mismatch(`tmpfs ${path}`, options, tmpfs[path]);
|
|
312
|
-
}
|
|
313
|
-
for (const [path, options] of Object.entries(tmpfs)) {
|
|
314
|
-
if (!(path in tmpfsAsked))
|
|
315
|
-
found.push(`tmpfs ${path}: none declared but /work and /run/agentrun, read back ${show(options)}`);
|
|
316
|
-
}
|
|
317
|
-
// A Docker computer takes a bind alone; check() refuses any other kind, so one here is drift, named by its kind only.
|
|
318
|
-
if (spec.mount !== undefined && spec.mount.kind !== "bind")
|
|
319
|
-
found.push(`mount: declared a mount of kind ${String(spec.mount.kind)}, which a Docker computer never makes`);
|
|
320
|
-
const bound = spec.mount?.kind === "bind" ? spec.mount.path : undefined;
|
|
321
|
-
// In create's order: the daemon read-only, then the run's folder read-write at /workspace when one was asked for, then
|
|
322
|
-
// the egress volume read-only for an allowlist.
|
|
323
|
-
// With the provider's volume option the daemon and the folder are the volume's subpaths (mountAsked).
|
|
324
|
-
const shared = expected.volume;
|
|
325
|
-
// The daemon's file is bound at DAEMON_IN_COMPUTER; with the volume option its staged directory is at /opt/agentrun.
|
|
326
|
-
const daemonAt = shared === undefined ? DAEMON_IN_COMPUTER : DAEMON_DIR_IN_COMPUTER;
|
|
327
|
-
const daemonAsked = mountAsked(expected.daemonPath, daemonAt, true, shared);
|
|
328
|
-
const folderAsked = bound === undefined ? undefined : mountAsked(bound, WORKSPACE, false, shared);
|
|
329
|
-
if (daemonAsked === undefined)
|
|
330
|
-
found.push(`daemon mount: ${expected.daemonPath} is not below the volume root ${shared?.root}, so create never mounts it`);
|
|
331
|
-
if (bound !== undefined && folderAsked === undefined)
|
|
332
|
-
found.push(`workspace mount: ${bound} is not below the volume root ${shared?.root}, so create never mounts it`);
|
|
333
|
-
const asked = [
|
|
334
|
-
...(daemonAsked === undefined ? [] : [daemonAsked]),
|
|
335
|
-
...(folderAsked === undefined ? [] : [folderAsked]),
|
|
336
|
-
...(allowed ? [{ Type: "volume", Source: volume, Target: EGRESS_MOUNT, ReadOnly: true }] : []),
|
|
337
|
-
];
|
|
338
|
-
const hostMounts = host.Mounts ?? [];
|
|
339
|
-
// An object (VolumeOptions) is the same when it holds the same fields; any other value, exactly.
|
|
340
|
-
const same = (value, want) => typeof want === "object" && want !== null
|
|
341
|
-
? typeof value === "object" && value !== null && Object.entries(value).every(([key, item]) => (key in want ? same(item, want[key]) : blank(item))) && Object.keys(want).every((key) => key in value)
|
|
342
|
-
: value === want;
|
|
343
|
-
const sameMount = (made, want) => made !== undefined &&
|
|
344
|
-
Object.entries(made).every(([key, value]) => (key in want ? same(value, want[key]) : blank(value))) &&
|
|
345
|
-
Object.keys(want).every((key) => made[key] !== undefined);
|
|
346
|
-
if (hostMounts.length !== asked.length || !asked.every((want, i) => sameMount(hostMounts[i], want)))
|
|
347
|
-
mismatch("HostConfig.Mounts", asked, host.Mounts);
|
|
348
|
-
for (const [field, value] of Object.entries(host)) {
|
|
349
|
-
if (HOST_ASKED.has(field) || HOST_IRRELEVANT.has(field))
|
|
350
|
-
continue;
|
|
351
|
-
const rule = HOST_DEFAULTS[field];
|
|
352
|
-
if (rule ? !rule[0](value) : !blank(value))
|
|
353
|
-
found.push(`${field}: must be ${rule ? rule[1] : "Docker's default (empty)"}, read back ${show(value)}`);
|
|
354
|
-
}
|
|
355
|
-
if (config.User !== expected.user)
|
|
356
|
-
mismatch("User", expected.user, config.User);
|
|
357
|
-
if (config.Image !== spec.image)
|
|
358
|
-
mismatch("Image", spec.image, config.Image);
|
|
359
|
-
const workdir = spec.workdir ?? WORK;
|
|
360
|
-
if (config.WorkingDir !== workdir)
|
|
361
|
-
mismatch("WorkingDir", workdir, config.WorkingDir);
|
|
362
|
-
const homes = (Array.isArray(config.Env) ? config.Env : []).filter((entry) => typeof entry === "string" && entry.startsWith("HOME="));
|
|
363
|
-
if (!sameList(homes, [`HOME=${WORK}`]))
|
|
364
|
-
mismatch("Env HOME", [`HOME=${WORK}`], homes);
|
|
365
|
-
for (const [field, value] of Object.entries(config)) {
|
|
366
|
-
if (!CONFIG_ASKED.has(field) && !CONFIG_IRRELEVANT.has(field) && !blank(value))
|
|
367
|
-
found.push(`${field}: must be Docker's default (empty), read back ${show(value)}`);
|
|
368
|
-
}
|
|
369
|
-
const apparmor = expected.apparmor ? "docker-default" : "";
|
|
370
|
-
if ((inspected?.AppArmorProfile ?? "") !== apparmor)
|
|
371
|
-
mismatch("AppArmorProfile", apparmor, inspected?.AppArmorProfile);
|
|
372
|
-
const label = inspected?.ProcessLabel ?? "";
|
|
373
|
-
if (expected.selinux ? !/^[^:]*:[^:]*:container_t:/.test(label) : label !== "") {
|
|
374
|
-
mismatch("ProcessLabel", expected.selinux ? "the container_t type" : "", inspected?.ProcessLabel);
|
|
375
|
-
}
|
|
376
|
-
const mounts = inspected?.Mounts ?? [];
|
|
377
|
-
const daemon = mounts.filter((mount) => mount.Destination === daemonAt);
|
|
378
|
-
const [only] = daemon;
|
|
379
|
-
// A bind shows its source; the volume's subpath shows as the volume (its subpath is HostConfig.Mounts', checked above).
|
|
380
|
-
const fits = (mount, path, rw) => mount !== undefined &&
|
|
381
|
-
mount.RW === rw &&
|
|
382
|
-
(shared === undefined ? mount.Type === "bind" && mount.Source === path && ["", "rprivate", undefined].includes(mount.Propagation) : mount.Type === "volume" && mount.Name === shared.name);
|
|
383
|
-
const how = (path, rw, at) => `declared ${path} ${shared === undefined ? "bound" : `mounted from the volume ${shared.name}`} ${rw ? "read-write" : "read-only"} at ${at}`;
|
|
384
|
-
if (daemon.length !== 1 || !fits(only, expected.daemonPath, false)) {
|
|
385
|
-
found.push(`daemon mount: ${how(expected.daemonPath, false, daemonAt)}, read back ${show(daemon)}`);
|
|
386
|
-
}
|
|
387
|
-
if (bound !== undefined) {
|
|
388
|
-
const workspace = mounts.filter((mount) => mount.Destination === WORKSPACE);
|
|
389
|
-
const [one] = workspace;
|
|
390
|
-
if (workspace.length !== 1 || !fits(one, bound, true)) {
|
|
391
|
-
found.push(`workspace mount: ${how(bound, true, WORKSPACE)}, read back ${show(workspace)}`);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
// The egress volume itself, its name, type and mode, is the network's read-back above.
|
|
395
|
-
const declared = ["the daemon's", ...(bound === undefined ? [] : ["the run folder's"]), ...(allowed ? ["the egress volume's"] : [])].join(" and ");
|
|
396
|
-
for (const mount of mounts) {
|
|
397
|
-
if (mount.Destination === daemonAt || (bound !== undefined && mount.Destination === WORKSPACE) || (allowed && mount.Destination === EGRESS_MOUNT))
|
|
398
|
-
continue;
|
|
399
|
-
found.push(`${mount.Type ?? "unknown"} mount: none declared but ${declared}, read back ${show(mount)}`);
|
|
400
|
-
}
|
|
401
|
-
if (!sameList(config.Entrypoint, [DAEMON_IN_COMPUTER]))
|
|
402
|
-
mismatch("Entrypoint", [DAEMON_IN_COMPUTER], config.Entrypoint);
|
|
403
|
-
const cmd = ["init", "--deadline", expected.deadline, ...(allowed ? [RELAY_FLAG, EGRESS_SOCKET] : [])];
|
|
404
|
-
if (!sameList(config.Cmd, cmd))
|
|
405
|
-
mismatch("Cmd", cmd, config.Cmd);
|
|
406
|
-
const labels = config.Labels ?? {};
|
|
407
|
-
if (labels[COMPUTER_LABEL] !== "1")
|
|
408
|
-
mismatch(`label ${COMPUTER_LABEL}`, "1", labels[COMPUTER_LABEL]);
|
|
409
|
-
if (labels[DEADLINE_LABEL] !== expected.deadline)
|
|
410
|
-
mismatch(`label ${DEADLINE_LABEL}`, expected.deadline, labels[DEADLINE_LABEL]);
|
|
411
|
-
for (const [key, value] of Object.entries(spec.labels ?? {})) {
|
|
412
|
-
if (labels[key] !== value)
|
|
413
|
-
mismatch(`label ${key}`, value, labels[key]);
|
|
414
|
-
}
|
|
415
|
-
return found;
|
|
416
|
-
}
|
package/dist/e2b.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { type DesktopOptions } from "./desktop.js";
|
|
|
2
2
|
import type { KindCapabilities } from "./kinds.js";
|
|
3
3
|
import { type MountKind } from "./mount.js";
|
|
4
4
|
import { type ProviderNote } from "./mount-archil.js";
|
|
5
|
-
import { type AttachedComputer, type CallContext, type ComputerCapabilities, type ComputerConnection, type ComputerInfo, type ComputerProvider, type ComputerRef, type ComputerSpec, type CreatedComputer, type NetworkPolicy, type NetworkSpec, type Refusal } from "./provider.js";
|
|
5
|
+
import { type AttachedComputer, type CallContext, type ComputerCapabilities, type ComputerConnection, type ComputerInfo, type ComputerProvider, type ComputerRef, type ComputerSpec, type CreatedComputer, type NetworkPolicy, type NetworkSpec, type Refusal, type ReleaseHow } from "./provider.js";
|
|
6
6
|
import { type ComputerErrorCode, type Result } from "./result.js";
|
|
7
7
|
import { type ScreenWatch, type ScreenWatchHandlers, type WatchOptions } from "./screen-watch.js";
|
|
8
8
|
/** What every SDK call is given: the key, the domain and the API URL explicitly, and debug false (index.mjs:1126-1152). */
|
|
@@ -208,10 +208,6 @@ export declare function connectionOptions({ apiKey, domain }: {
|
|
|
208
208
|
export declare function create(options: E2BOptions): Promise<E2BProvider>;
|
|
209
209
|
/** The conformance CLI's module for E2B: its live switch, the run's 30-minute cap, its template and the drifted twin. */
|
|
210
210
|
export declare const conformance: () => Promise<typeof import("./conformance/e2b.js")>;
|
|
211
|
-
/** E2B Desktop's template: a screen with an X server, the default for kind desktop. */
|
|
212
|
-
export declare const E2B_DESKTOP_TEMPLATE = "desktop";
|
|
213
|
-
/** E2B's plain template: no screen, the default for kind linux (a sandbox). */
|
|
214
|
-
export declare const E2B_BASE_TEMPLATE = "base";
|
|
215
211
|
/** The mount kinds an E2B computer takes, as capabilities().mount declares them: the run's folder on an Archil disk. */
|
|
216
212
|
export declare const MOUNT: readonly MountKind[];
|
|
217
213
|
/** The machine kind and groups of each configuration: kind linux (the plain template), and kind desktop (the default). */
|
|
@@ -333,5 +329,5 @@ export declare class E2BProvider implements ComputerProvider {
|
|
|
333
329
|
* whatever that answers. A folder not let go cleanly loses nothing (every call that changed it synced, and the next
|
|
334
330
|
* claim revokes the hold), so it is said through onNote, and the release succeeds once the sandbox is gone.
|
|
335
331
|
*/
|
|
336
|
-
release(ref: ComputerRef, how:
|
|
332
|
+
release(ref: ComputerRef, how: ReleaseHow, { signal }?: CallContext): Promise<Result<void>>;
|
|
337
333
|
}
|
package/dist/e2b.js
CHANGED
|
@@ -12,17 +12,20 @@ import { fileURLToPath } from "node:url";
|
|
|
12
12
|
import { childCommands, daemonDrift } from "./child.js";
|
|
13
13
|
import { OWN_NETWORK_ONLY, readOwnNetwork, TOOL_USER } from "./isolation.js";
|
|
14
14
|
import { DaemonClient } from "./client.js";
|
|
15
|
+
import { E2B, E2B_BASE_TEMPLATE, E2B_DESKTOP_TEMPLATE } from "./descriptors/e2b.js";
|
|
15
16
|
import { DESKTOP_GROUPS, desktopOf, startDisplay } from "./desktop.js";
|
|
16
17
|
import { COMPUTER_LABEL, DAEMON_IN_COMPUTER, DEADLINE_LABEL, helloDrift, probeNetworkDrift, probeNotes, probeReportOf, WORK } from "./drift.js";
|
|
17
18
|
import { releaseOlder } from "./janitor.js";
|
|
18
19
|
import { RUN_LABEL } from "./labels.js";
|
|
19
20
|
import { checkMount, readBackOf } from "./mount.js";
|
|
20
21
|
import { ARCHIL_HELPER, ARCHIL_MOUNT_LABEL, ARCHIL_TOOL_UID, archilLabels, archilMount, archilRefusals, archilRelease, claimEpoch, mountDrift, readArchilMount, recordedArchil as recordedArchilOf, recordedMount, syncingClient, } from "./mount-archil.js";
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
22
|
+
import { checkGpu, checkTenure, runLifetimeMs, } from "./provider.js";
|
|
23
|
+
import { failFor, ok, vendorFail } from "./result.js";
|
|
23
24
|
import { daemonWatch } from "./screen-watch.js";
|
|
24
25
|
import { countTested } from "./test-connection.js";
|
|
25
26
|
import { waitUntil } from "./wait.js";
|
|
27
|
+
/** This module's failures: one with code vendor names E2B. */
|
|
28
|
+
const fail = failFor("e2b");
|
|
26
29
|
/** Not a literal, so no type checker or bundler resolves the SDK from this package. */
|
|
27
30
|
const E2B_PACKAGE = "e2b";
|
|
28
31
|
const DEFAULT_DOMAIN = "e2b.app";
|
|
@@ -65,10 +68,6 @@ const VERSION = JSON.parse(readFileSync(new URL("../package.json", import.meta.u
|
|
|
65
68
|
const NAME = /^computer-[0-9a-f]{12}$/;
|
|
66
69
|
const SANDBOX_ID = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/;
|
|
67
70
|
const TEMPLATE = /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$/;
|
|
68
|
-
/** E2B Desktop's template: a screen with an X server, the default for kind desktop. */
|
|
69
|
-
export const E2B_DESKTOP_TEMPLATE = "desktop";
|
|
70
|
-
/** E2B's plain template: no screen, the default for kind linux (a sandbox). */
|
|
71
|
-
export const E2B_BASE_TEMPLATE = "base";
|
|
72
71
|
const NAME_LABEL = `${COMPUTER_LABEL}.name`;
|
|
73
72
|
/** The template create was asked for: E2B reports its id, and the alias only sometimes. */
|
|
74
73
|
const IMAGE_LABEL = `${COMPUTER_LABEL}.image`;
|
|
@@ -99,14 +98,11 @@ const DEFAULTS = {
|
|
|
99
98
|
mountMs: 120_000,
|
|
100
99
|
};
|
|
101
100
|
/** The mount kinds an E2B computer takes, as capabilities().mount declares them: the run's folder on an Archil disk. */
|
|
102
|
-
export const MOUNT =
|
|
101
|
+
export const MOUNT = E2B.mounts;
|
|
103
102
|
/** The user an Archil computer's tools run as: the image's agentrun-tool, with no sudo and no capability. */
|
|
104
103
|
const ARCHIL_USER = `${ARCHIL_TOOL_UID}:${ARCHIL_TOOL_UID}`;
|
|
105
104
|
/** The machine kind and groups of each configuration: kind linux (the plain template), and kind desktop (the default). */
|
|
106
|
-
export const CAPABILITIES =
|
|
107
|
-
{ kind: "linux", groups: ["exec", "files", "processes"] },
|
|
108
|
-
{ kind: "desktop", groups: ["exec", "files", "processes", ...DESKTOP_GROUPS] },
|
|
109
|
-
];
|
|
105
|
+
export const CAPABILITIES = E2B.capabilities;
|
|
110
106
|
const RELEASE_POLL_MAX_MS = 5_000;
|
|
111
107
|
const LISTED_POLL_MS = 150;
|
|
112
108
|
const LISTED_ROUNDS = 2;
|
|
@@ -132,7 +128,7 @@ const STAGING = "/tmp/agentrun-computerd-";
|
|
|
132
128
|
const DEFAULT_PROBE_TARGETS = ["1.1.1.1:443", "8.8.8.8:443", "[2606:4700:4700::1111]:443", "1.1.1.1:53/udp", "[2606:4700:4700::1111]:53/udp"];
|
|
133
129
|
/** A probe target: host:port, over TCP, or host:port/udp, a DNS query over UDP. */
|
|
134
130
|
const TARGET = /^(?:\[[0-9A-Fa-f:.]+\]|[A-Za-z0-9.-]+):[0-9]{1,5}(?:\/udp)?$/;
|
|
135
|
-
const SPEC_FIELDS = new Set(["image", "lifetimeMs", "network", "labels", "mount"]);
|
|
131
|
+
const SPEC_FIELDS = new Set(["image", "lifetimeMs", "network", "labels", "mount", "gpu"]);
|
|
136
132
|
const NUL = "a NUL byte cannot be sent to E2B";
|
|
137
133
|
const FIXED = "an E2B computer's network is fixed at create: create a new computer";
|
|
138
134
|
const PUBLIC = "publicStream is no longer an option: an E2B computer never takes public traffic, which would open every port in it to anyone with its address, and its screen is streamed through agentrun, never a vendor URL";
|
|
@@ -174,7 +170,7 @@ function codeOf(error) {
|
|
|
174
170
|
return "limit";
|
|
175
171
|
if (name === "TimeoutError" || name === "SandboxUnreachableError")
|
|
176
172
|
return "timeout";
|
|
177
|
-
return "
|
|
173
|
+
return "vendor";
|
|
178
174
|
}
|
|
179
175
|
/** Settles with the promise's result, or a timeout or abort in words once ms pass or signal aborts. */
|
|
180
176
|
function race(promise, what, ms, signal) {
|
|
@@ -406,7 +402,7 @@ export class E2BProvider {
|
|
|
406
402
|
return {
|
|
407
403
|
kind: this.#kind,
|
|
408
404
|
lifetime: "vendor",
|
|
409
|
-
network: [
|
|
405
|
+
network: [...E2B.network],
|
|
410
406
|
networkReadBack: true,
|
|
411
407
|
isolation: "microvm",
|
|
412
408
|
os: "linux",
|
|
@@ -430,7 +426,7 @@ export class E2BProvider {
|
|
|
430
426
|
}
|
|
431
427
|
if (typeof image !== "string" || !TEMPLATE.test(image))
|
|
432
428
|
refuse("image", `an image is required: the name or id of an E2B template, such as "${E2B_DESKTOP_TEMPLATE}" (E2B Desktop) or "${E2B_BASE_TEMPLATE}"`);
|
|
433
|
-
refusals.push(...
|
|
429
|
+
refusals.push(...checkTenure(given, this.capabilities(), "E2B"));
|
|
434
430
|
if (network === "open" || (typeof network === "object" && network !== null && "allow" in network))
|
|
435
431
|
refuse("network", OWN_NETWORK_ONLY);
|
|
436
432
|
else if (network !== "none")
|
|
@@ -441,6 +437,7 @@ export class E2BProvider {
|
|
|
441
437
|
if (bad)
|
|
442
438
|
refuse("labels", bad);
|
|
443
439
|
}
|
|
440
|
+
refusals.push(...checkGpu(given.gpu, this.capabilities()));
|
|
444
441
|
for (const [field, value] of Object.entries(given)) {
|
|
445
442
|
if (SPEC_FIELDS.has(field) || value === undefined)
|
|
446
443
|
continue;
|
|
@@ -489,10 +486,10 @@ export class E2BProvider {
|
|
|
489
486
|
return fail("aborted", "create was aborted before E2B was called");
|
|
490
487
|
const name = `computer-${randomBytes(6).toString("hex")}`;
|
|
491
488
|
const now = Date.now();
|
|
492
|
-
const deadline = new Date(now + spec
|
|
489
|
+
const deadline = new Date(now + runLifetimeMs(spec)).toISOString();
|
|
493
490
|
const maxDeadline = new Date(now + this.#maxLifetimeMs).toISOString();
|
|
494
491
|
// E2B kills the sandbox at its timeout, the lifetime in the whole seconds it takes (index.mjs:502-504).
|
|
495
|
-
const timeoutMs = Math.ceil(spec
|
|
492
|
+
const timeoutMs = Math.ceil(runLifetimeMs(spec) / 1000) * 1000;
|
|
496
493
|
const metadata = {
|
|
497
494
|
...spec.labels,
|
|
498
495
|
[COMPUTER_LABEL]: "1",
|
|
@@ -920,7 +917,7 @@ export class E2BProvider {
|
|
|
920
917
|
return fail("timeout", `the daemon in ${name} did not answer hello within ${seconds(helloMs)}`);
|
|
921
918
|
if (hello.error.code !== "gone")
|
|
922
919
|
return hello;
|
|
923
|
-
return { ...
|
|
920
|
+
return { ...vendorFail("e2b", `cannot reach the daemon in ${name}: ${stderr.trim() || hello.error.message}`), notListening: true };
|
|
924
921
|
}
|
|
925
922
|
return ok({ client, hello: hello.value, close });
|
|
926
923
|
}
|
|
@@ -1040,7 +1037,7 @@ export class E2BProvider {
|
|
|
1040
1037
|
if (!opened.ok)
|
|
1041
1038
|
return opened;
|
|
1042
1039
|
const { kind, groups } = this.capabilities();
|
|
1043
|
-
const drifted = helloDrift(opened.value.hello, { version: VERSION, kind, groups, arch: ARCH });
|
|
1040
|
+
const drifted = helloDrift(opened.value.hello, { version: VERSION, kind, groups, arch: ARCH, fence: true });
|
|
1044
1041
|
// An Archil computer's client syncs the run's folder after every call that may change it, before it answers.
|
|
1045
1042
|
if (drifted.length === 0)
|
|
1046
1043
|
return recordedArchil(found.value.metadata) === undefined ? opened : ok({ ...opened.value, client: syncingClient(opened.value.client) });
|
|
@@ -1163,13 +1160,13 @@ export class E2BProvider {
|
|
|
1163
1160
|
const found = new Map();
|
|
1164
1161
|
for (let page = 0; paginator.hasNext; page++) {
|
|
1165
1162
|
if (page >= MAX_PAGES)
|
|
1166
|
-
return
|
|
1163
|
+
return vendorFail("e2b", `Sandbox.list ran past ${MAX_PAGES} pages`);
|
|
1167
1164
|
const left = Math.max(1, until - Date.now());
|
|
1168
1165
|
const items = await call("Sandbox.list", () => paginator.nextItems({ requestTimeoutMs: Math.min(requestMs, left), ...(signal ? { signal } : {}) }), left, signal);
|
|
1169
1166
|
if (!items.ok)
|
|
1170
1167
|
return boundBy(items, given === undefined ? undefined : left, requestMs);
|
|
1171
1168
|
if (!Array.isArray(items.value))
|
|
1172
|
-
return
|
|
1169
|
+
return vendorFail("e2b", "Sandbox.list: a page that is not a list of sandboxes");
|
|
1173
1170
|
for (const sb of items.value)
|
|
1174
1171
|
if (typeof sb?.sandboxId === "string")
|
|
1175
1172
|
found.set(sb.sandboxId, sb);
|
|
@@ -1194,7 +1191,7 @@ export class E2BProvider {
|
|
|
1194
1191
|
if (!items.ok)
|
|
1195
1192
|
return countTested("E2B", fail(items.error.code, items.error.message));
|
|
1196
1193
|
if (!Array.isArray(items.value))
|
|
1197
|
-
return countTested("E2B",
|
|
1194
|
+
return countTested("E2B", vendorFail("e2b", "Sandbox.list: a page that is not a list of sandboxes"));
|
|
1198
1195
|
const count = items.value.filter((sb) => typeof sb?.sandboxId === "string" && ours(sb.metadata)).length;
|
|
1199
1196
|
return countTested("E2B", ok({ count, more: paginator.hasNext }));
|
|
1200
1197
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,21 +7,20 @@ export { type ActionFailure, type CheckActionsOptions, checkActions, isKey } fro
|
|
|
7
7
|
export { pullTar, pullTarStream, pushTar, readFile, writeFile, type PulledTar } from "./files.js";
|
|
8
8
|
export { listProcesses, readAll, type ReadAllResult } from "./processes.js";
|
|
9
9
|
export { type ActionMapper, createActionMapper, daemonWatch, redactWords, type ScreenFrame, type ScreenFrames, type ScreenWatch, ScreenWatchError, type ScreenWatchHandlers, toAction, type ViewerEvent, type WatchEndCode, watchEndCode, type WatchOptions, watchScreen, } from "./screen-watch.js";
|
|
10
|
-
export { type DockerDesktopOptions, type DockerEgressOptions, DockerProvider, type DockerProviderOptions } from "./docker.js";
|
|
11
10
|
export { type DockerVolume, VOLUME_SUBPATH_ENGINE } from "./docker/volume.js";
|
|
12
11
|
export { DEFAULT_DOCKER_IMAGE, DOCKER_BASE, DOCKER_RECIPE, DOCKER_RECIPE_HAS, ensureImage, type EnsureImageOptions, IMAGE_REPOSITORY, IMAGE_TIMEOUT_MS, type ImageSource, imageSourceProblem, type Making, RECIPE_LABEL, recipeHash, recipeTag, } from "./docker/image.js";
|
|
13
12
|
export { EGRESS_IMAGE, EGRESS_LABEL, EGRESS_MOUNT, EGRESS_SOCKET } from "./docker/egress.js";
|
|
14
|
-
export { DAYTONA_DEFAULT_SNAPSHOT, DaytonaProvider, type DaytonaProviderOptions, type DaytonaTimeouts, type WebSocketFactory, type WebSocketLike } from "./daytona.js";
|
|
15
|
-
export { ModalProvider, type ModalApp, type ModalByteSink, type ModalCreateParams, type ModalImage, type ModalProcess, type ModalProviderOptions, type ModalSandbox, type ModalSdk, type ModalTimeouts, } from "./modal.js";
|
|
16
13
|
export { ARCHIL_HELPER, ARCHIL_MOUNT_LABEL, ARCHIL_SYNC_SOCKET, ARCHIL_TOOL_UID, ARCHIL_TOOL_USER, ARCHIL_VERSION, type ArchilMount, type ArchilMountOptions, type ArchilRoot, type ProviderNote, archilLabels, archilMount, archilReadBack, archilRefusals, archilRelease, claimEpoch, helperSha256, mountDrift, mountWords, type RecordedArchil, readArchilMount, recordedArchil, recordedMount, syncingClient, } from "./mount-archil.js";
|
|
17
|
-
export {
|
|
18
|
-
export {
|
|
19
|
-
export {
|
|
20
|
-
export {
|
|
14
|
+
export { type BrowserStream, BrowserVendorError, CREATE_LABEL, causeOf, memoryUrls, RECOVER_MS, type ReleaseConfirm, type RestReply, type UrlStore, } from "./browser.js";
|
|
15
|
+
export { CHROME_ENV, CHROME_FLAGS, checkChrome, chromeFence, findChrome, killTree, NO_CHROME } from "./chrome.js";
|
|
16
|
+
export { DAEMON_IN_COMPUTER, helloDrift, type HelloExpected } from "./drift.js";
|
|
17
|
+
export { drift, hostOf, inspectDrift, mountOf, networkOf, type DockerHost, type DockerInfo, type DockerInspect, type DriftExpected } from "./docker/inspect.js";
|
|
21
18
|
export { type ReleasedOlder, releaseOlder, sweep, type SweepOptions, type Swept } from "./janitor.js";
|
|
22
|
-
export { EPOCH_LABEL, epochOf, epochProblem, RUN_LABEL, runLabels, runProblem } from "./labels.js";
|
|
19
|
+
export { EPOCH_LABEL, epochOf, epochProblem, IDLE_TTL_LABEL, OWNER_LABEL, ownerLabels, ownerOf, RUN_HASH_LABEL, RUN_LABEL, runHash, runLabels, runProblem } from "./labels.js";
|
|
23
20
|
export { waitUntil, type WaitOptions } from "./wait.js";
|
|
24
|
-
export { type ConformanceModule, isProviderId, type ProviderEnv, providerFor, type ProviderId, providerIds, type ProviderModule, providerModule, type ProviderOptions, providers, } from "./providers.js";
|
|
21
|
+
export { type BuiltinProviderId, type ConformanceModule, descriptorOf, isProviderId, type ProviderEnv, providerFor, type ProviderId, providerIds, type ProviderModule, providerModule, type ProviderOptions, providers, } from "./providers.js";
|
|
22
|
+
export { type DescriptorKey, type DescriptorSetting, defineProvider, descriptorProblems, type ParkedConfiguration, type ProviderDescriptor } from "./descriptor.js";
|
|
23
|
+
export { BROWSER_IMAGE, BROWSERBASE, DAYTONA, DAYTONA_DEFAULT_SNAPSHOT, DAYTONA_GPU_SNAPSHOT, DESCRIPTORS, DOCKER, E2B, E2B_BASE_TEMPLATE, E2B_DESKTOP_TEMPLATE, KERNEL, LOCAL, MODAL, MODAL_DEFAULT_IMAGE, ORGO, ORGO_BASE_IMAGE, PHONE_GROUPS, PHONE_HARNESS, PHONE_IMAGE, } from "./descriptors/index.js";
|
|
25
24
|
export type { PhoneLedger, PhoneLedgerEntry } from "./phone-harness.js";
|
|
26
|
-
export { type ComputerSettingKind, type KindCapabilities, kindOf, type ProviderEntry,
|
|
25
|
+
export { type ComputerSettingKind, configurationOf, entryOf, imagesOf, type KindCapabilities, kindOf, type ProviderEntry, PROVIDERS, SETTING_KIND_NAMES, SETTING_KINDS, type SettingKindSpec, serves, servingRefusals, type TestConnection, type TestConnectionOptions, } from "./kinds.js";
|
|
27
26
|
export * from "./conformance/index.js";
|