@parcha/agentrun-computer 0.1.0-beta.40 → 0.1.0-beta.42

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.
Files changed (96) hide show
  1. package/NOTICE +2 -0
  2. package/README.md +285 -28
  3. package/box/Dockerfile +6 -4
  4. package/box/README.md +10 -2
  5. package/box/build-daytona.py +3 -1
  6. package/box/build-e2b.mjs +1 -1
  7. package/box/install.sh +68 -7
  8. package/dist/attach.d.ts +46 -1
  9. package/dist/attach.js +48 -4
  10. package/dist/box-image.d.ts +1 -1
  11. package/dist/box-image.js +1 -1
  12. package/dist/boxd.d.ts +126 -0
  13. package/dist/boxd.js +418 -0
  14. package/dist/cloudflare.d.ts +32 -0
  15. package/dist/cloudflare.js +179 -0
  16. package/dist/computerd-linux-amd64 +0 -0
  17. package/dist/computerd-linux-arm64 +0 -0
  18. package/dist/computerd.json +2 -2
  19. package/dist/conformance/boxd.d.ts +77 -0
  20. package/dist/conformance/boxd.js +113 -0
  21. package/dist/conformance/cases/isolation.js +1 -17
  22. package/dist/conformance/cases/provider.js +42 -26
  23. package/dist/conformance/cli.js +4 -1
  24. package/dist/conformance/cloudflare.d.ts +42 -0
  25. package/dist/conformance/cloudflare.js +54 -0
  26. package/dist/conformance/daytona.d.ts +25 -0
  27. package/dist/conformance/daytona.js +26 -1
  28. package/dist/conformance/dial-only.d.ts +6 -0
  29. package/dist/conformance/dial-only.js +9 -0
  30. package/dist/conformance/e2b.d.ts +12 -3
  31. package/dist/conformance/e2b.js +21 -4
  32. package/dist/conformance/exec-stream.js +14 -6
  33. package/dist/conformance/fly.d.ts +52 -0
  34. package/dist/conformance/fly.js +52 -0
  35. package/dist/conformance/modal.d.ts +15 -2
  36. package/dist/conformance/modal.js +36 -3
  37. package/dist/conformance/morph.d.ts +59 -0
  38. package/dist/conformance/morph.js +95 -0
  39. package/dist/conformance/phone-harness.js +2 -2
  40. package/dist/conformance/runner.js +5 -1
  41. package/dist/conformance/sweep.d.ts +1 -1
  42. package/dist/conformance/sweep.js +1 -1
  43. package/dist/conformance/types.d.ts +21 -0
  44. package/dist/daytona.d.ts +8 -1
  45. package/dist/daytona.js +124 -101
  46. package/dist/descriptor.d.ts +22 -1
  47. package/dist/descriptor.js +18 -0
  48. package/dist/descriptors/boxd.d.ts +52 -0
  49. package/dist/descriptors/boxd.js +29 -0
  50. package/dist/descriptors/cloudflare.d.ts +21 -0
  51. package/dist/descriptors/cloudflare.js +29 -0
  52. package/dist/descriptors/daytona.d.ts +12 -3
  53. package/dist/descriptors/daytona.js +15 -7
  54. package/dist/descriptors/e2b.d.ts +4 -0
  55. package/dist/descriptors/e2b.js +3 -0
  56. package/dist/descriptors/fly.d.ts +19 -0
  57. package/dist/descriptors/fly.js +28 -0
  58. package/dist/descriptors/index.d.ts +121 -2
  59. package/dist/descriptors/index.js +7 -2
  60. package/dist/descriptors/modal.d.ts +3 -0
  61. package/dist/descriptors/modal.js +7 -2
  62. package/dist/descriptors/morph.d.ts +15 -0
  63. package/dist/descriptors/morph.js +21 -0
  64. package/dist/descriptors/phone-harness.d.ts +1 -0
  65. package/dist/descriptors/phone-harness.js +2 -0
  66. package/dist/e2b.d.ts +7 -1
  67. package/dist/e2b.js +87 -44
  68. package/dist/fly.d.ts +43 -0
  69. package/dist/fly.js +245 -0
  70. package/dist/host.d.ts +52 -48
  71. package/dist/hosted/framed-exec.d.ts +8 -19
  72. package/dist/hosted/framed-exec.js +21 -87
  73. package/dist/hosted/process.d.ts +21 -0
  74. package/dist/hosted/process.js +37 -2
  75. package/dist/hosted/provider.d.ts +32 -6
  76. package/dist/hosted/provider.js +239 -236
  77. package/dist/hosted/rest.d.ts +19 -0
  78. package/dist/hosted/rest.js +76 -0
  79. package/dist/hosted/scripts.d.ts +52 -8
  80. package/dist/hosted/scripts.js +118 -23
  81. package/dist/hosted/ssh-exec.d.ts +9 -7
  82. package/dist/hosted/ssh-exec.js +93 -54
  83. package/dist/hosted/values.d.ts +5 -0
  84. package/dist/hosted/values.js +9 -0
  85. package/dist/index.d.ts +3 -3
  86. package/dist/index.js +4 -4
  87. package/dist/kinds.d.ts +2 -0
  88. package/dist/modal.d.ts +6 -0
  89. package/dist/modal.js +40 -17
  90. package/dist/morph.d.ts +65 -0
  91. package/dist/morph.js +495 -0
  92. package/dist/phone-harness.d.ts +15 -5
  93. package/dist/phone-harness.js +50 -15
  94. package/dist/providers.d.ts +4 -2
  95. package/dist/screen-watch.js +2 -2
  96. package/package.json +20 -2
@@ -0,0 +1,77 @@
1
+ import { type BoxdOptions, type BoxdProvider } from "../boxd.js";
2
+ import type { MachineHost } from "../host.js";
3
+ /** The environment this module reads, by name, each for the option its comment names, the live switch and the run's image. */
4
+ export declare const BOXD_ENV: {
5
+ readonly live: "AGENTRUN_COMPUTER_LIVE_BOXD";
6
+ /** The image every computer of the run starts from: "default" (boxd's own), or a snapshot's name; unset, a desktop's is the desktop snapshot. */
7
+ readonly image: "COMPUTER_BOXD_IMAGE";
8
+ /** apiKey, required: the boxd API key. */
9
+ readonly key: "COMPUTER_BOXD_API_KEY";
10
+ /** org: the org machines are made in; default the key's own. */
11
+ readonly org: "COMPUTER_BOXD_ORG";
12
+ /** region: fra, nyc, ...; default the API's home region. */
13
+ readonly region: "COMPUTER_BOXD_REGION";
14
+ /** daemonPath: the daemon binary; default this package's dist/computerd-linux-amd64. */
15
+ readonly daemon: "COMPUTER_BOXD_DAEMON";
16
+ /** kind: linux (default) or desktop. */
17
+ readonly kind: "COMPUTER_BOXD_KIND";
18
+ /** daemonUser: uid:gid the daemon runs as; default 2510:2510. */
19
+ readonly user: "COMPUTER_BOXD_USER";
20
+ };
21
+ /** The names this module reads, under the conformance modules' common name (ConformanceModule.ENV). */
22
+ export declare const ENV: {
23
+ readonly live: "AGENTRUN_COMPUTER_LIVE_BOXD";
24
+ /** The image every computer of the run starts from: "default" (boxd's own), or a snapshot's name; unset, a desktop's is the desktop snapshot. */
25
+ readonly image: "COMPUTER_BOXD_IMAGE";
26
+ /** apiKey, required: the boxd API key. */
27
+ readonly key: "COMPUTER_BOXD_API_KEY";
28
+ /** org: the org machines are made in; default the key's own. */
29
+ readonly org: "COMPUTER_BOXD_ORG";
30
+ /** region: fra, nyc, ...; default the API's home region. */
31
+ readonly region: "COMPUTER_BOXD_REGION";
32
+ /** daemonPath: the daemon binary; default this package's dist/computerd-linux-amd64. */
33
+ readonly daemon: "COMPUTER_BOXD_DAEMON";
34
+ /** kind: linux (default) or desktop. */
35
+ readonly kind: "COMPUTER_BOXD_KIND";
36
+ /** daemonUser: uid:gid the daemon runs as; default 2510:2510. */
37
+ readonly user: "COMPUTER_BOXD_USER";
38
+ };
39
+ /** What this module reads from the environment: the key, and each other option whose name is set. */
40
+ export type BoxdSettings = Pick<BoxdOptions, "apiKey" | "org" | "region" | "daemonPath" | "kind" | "daemonUser">;
41
+ /**
42
+ * The provider's options this module reads from env, each only when its name is set; throws in words without the key,
43
+ * never echoing it. create() checks the rest.
44
+ */
45
+ export declare function settingsFromEnv(env?: Record<string, string | undefined>): BoxdSettings;
46
+ /** The longest lifetime a computer of a run may ask for. */
47
+ export declare const CONFORMANCE_MAX_LIFETIME_MS: number;
48
+ /** For the run's report: what this configuration means for the suite. */
49
+ export declare const conformanceNotes: string[];
50
+ export interface BoxdModuleOptions extends Pick<BoxdOptions, "Boxd" | "daemonPath" | "timeouts"> {
51
+ /** Where the settings are read; default process.env. */
52
+ env?: Record<string, string | undefined>;
53
+ /** Builds this package's daemon for linux/amd64 stamped with version, and gives its path; default go build. */
54
+ buildDaemon?: (version: string) => Promise<string>;
55
+ }
56
+ /**
57
+ * The image every computer of the run starts from: COMPUTER_BOXD_IMAGE, else boxd's own, else for kind desktop the
58
+ * desktop snapshot, which the run's provider finds or builds in the key's org first (prepareImage, live).
59
+ */
60
+ export declare function conformanceImage(options?: BoxdModuleOptions, { signal }?: {
61
+ signal?: AbortSignal;
62
+ }): Promise<string>;
63
+ /** The provider the CLI runs; throws in words without the live switch, or when a setting is missing or wrong. */
64
+ export declare function createProvider({ env, Boxd, daemonPath, timeouts }?: BoxdModuleOptions): Promise<BoxdProvider>;
65
+ /**
66
+ * The boxd host the live sweep (sweep.ts) lists and deletes through, from the same settings; it needs no live switch,
67
+ * since the sweep makes nothing, and it calls nothing until the sweep does.
68
+ */
69
+ export declare function createHost({ env, Boxd }?: Pick<BoxdModuleOptions, "env" | "Boxd">): Promise<MachineHost>;
70
+ /**
71
+ * Where the sweep lists, in words: the org and region the settings name, under the key named by its sha256 prefix alone.
72
+ * A before file listed with another key, org or region would make every computer there read as new, so the sweep
73
+ * refuses it.
74
+ */
75
+ export declare function sweepScope({ env }?: Pick<BoxdModuleOptions, "env">): string;
76
+ /** The same provider uploading a daemon that reports version <version>-drift, for the drift.version case. */
77
+ export declare function createDriftedProvider({ env, Boxd, timeouts, buildDaemon }?: BoxdModuleOptions): Promise<BoxdProvider>;
@@ -0,0 +1,113 @@
1
+ // boxd for the conformance CLI: `npm run conformance -w @parcha/agentrun-computer -- --provider boxd [--image <snapshot>]`.
2
+ // It makes real machines, so it runs only with AGENTRUN_COMPUTER_LIVE_BOXD=1 and your own key, under
3
+ // COMPUTER_BOXD_API_KEY. The provider reads no environment: this module reads its own COMPUTER_BOXD_* names (never
4
+ // BOXD_API_KEY, which may hold another account's key) and passes each to create() as its option. The live switch is
5
+ // checked first, before any other setting is read. The live sweep (sweep.ts, --provider boxd) reads the same names
6
+ // through createHost, which needs no live switch: it makes nothing; sweepScope names the key, org and region a before
7
+ // file must have been listed from.
8
+ //
9
+ // The daemon is uploaded into each machine (dist/computerd-linux-amd64, `npm run build:daemon`), so a run publishes
10
+ // nothing. The drifted provider uploads a daemon built with Go as version <version>-drift. Every computer of a run has
11
+ // a deadline of at most 30 minutes, and the runner sweeps the run's computers by its label when it ends.
12
+ import { createHash } from "node:crypto";
13
+ import { BOXD_DEFAULT_IMAGE } from "../descriptors/boxd.js";
14
+ import { create } from "../boxd.js";
15
+ import { buildDriftDaemon, DRIFT_VERSION } from "./drift-daemon.js";
16
+ /** The environment this module reads, by name, each for the option its comment names, the live switch and the run's image. */
17
+ export const BOXD_ENV = {
18
+ live: "AGENTRUN_COMPUTER_LIVE_BOXD",
19
+ /** The image every computer of the run starts from: "default" (boxd's own), or a snapshot's name; unset, a desktop's is the desktop snapshot. */
20
+ image: "COMPUTER_BOXD_IMAGE",
21
+ /** apiKey, required: the boxd API key. */
22
+ key: "COMPUTER_BOXD_API_KEY",
23
+ /** org: the org machines are made in; default the key's own. */
24
+ org: "COMPUTER_BOXD_ORG",
25
+ /** region: fra, nyc, ...; default the API's home region. */
26
+ region: "COMPUTER_BOXD_REGION",
27
+ /** daemonPath: the daemon binary; default this package's dist/computerd-linux-amd64. */
28
+ daemon: "COMPUTER_BOXD_DAEMON",
29
+ /** kind: linux (default) or desktop. */
30
+ kind: "COMPUTER_BOXD_KIND",
31
+ /** daemonUser: uid:gid the daemon runs as; default 2510:2510. */
32
+ user: "COMPUTER_BOXD_USER",
33
+ };
34
+ /** The names this module reads, under the conformance modules' common name (ConformanceModule.ENV). */
35
+ export const ENV = BOXD_ENV;
36
+ /**
37
+ * The provider's options this module reads from env, each only when its name is set; throws in words without the key,
38
+ * never echoing it. create() checks the rest.
39
+ */
40
+ export function settingsFromEnv(env = process.env) {
41
+ const apiKey = env[BOXD_ENV.key];
42
+ if (apiKey === undefined || apiKey === "")
43
+ throw new Error(`set ${BOXD_ENV.key} to a boxd API key: the conformance module reads it there and nowhere else, never from BOXD_API_KEY`);
44
+ const org = env[BOXD_ENV.org] || undefined;
45
+ const region = env[BOXD_ENV.region] || undefined;
46
+ const daemonPath = env[BOXD_ENV.daemon] || undefined;
47
+ const kind = env[BOXD_ENV.kind] || undefined;
48
+ const daemonUser = env[BOXD_ENV.user] || undefined;
49
+ return {
50
+ apiKey,
51
+ ...(org === undefined ? {} : { org }),
52
+ ...(region === undefined ? {} : { region }),
53
+ ...(daemonPath === undefined ? {} : { daemonPath }),
54
+ // create() refuses any other kind in words.
55
+ ...(kind === undefined ? {} : { kind: kind }),
56
+ ...(daemonUser === undefined ? {} : { daemonUser }),
57
+ };
58
+ }
59
+ /** The longest lifetime a computer of a run may ask for. */
60
+ export const CONFORMANCE_MAX_LIFETIME_MS = 30 * 60_000;
61
+ /** For the run's report: what this configuration means for the suite. */
62
+ export const conformanceNotes = [
63
+ "boxd: every computer is an isolated boxd machine with the egress allowlist none, no standby and no hibernation; the daemon is a child of boxd's own agent, started as a detached root command; lifetime is the janitor's, by the deadline label, capped at 30 minutes for the run; no stream() (a screen is streamed through agentrun), so screen.stream is skipped. Kind desktop (COMPUTER_BOXD_KIND=desktop) starts from agentrun-desktop-<recipe hash>, boxd's own image with Xfce's text editor added, a snapshot the run's provider finds or builds in the key's org first (prepareImage), with Xvfb on :0 started through the daemon as the tool user.",
64
+ ];
65
+ function live(env) {
66
+ if (env[BOXD_ENV.live] !== "1")
67
+ throw new Error(`the boxd conformance module makes real machines: set ${BOXD_ENV.live}=1, with your own key, to run it`);
68
+ }
69
+ /**
70
+ * The image every computer of the run starts from: COMPUTER_BOXD_IMAGE, else boxd's own, else for kind desktop the
71
+ * desktop snapshot, which the run's provider finds or builds in the key's org first (prepareImage, live).
72
+ */
73
+ export async function conformanceImage(options = {}, { signal } = {}) {
74
+ const { env = process.env } = options;
75
+ const named = env[BOXD_ENV.image];
76
+ if (named)
77
+ return named;
78
+ if (env[BOXD_ENV.kind] !== "desktop")
79
+ return BOXD_DEFAULT_IMAGE;
80
+ const ready = await (await createProvider(options)).prepareImage(signal ? { signal } : {});
81
+ if (!ready.ok)
82
+ throw new Error(ready.error.message);
83
+ return ready.value;
84
+ }
85
+ /** The provider the CLI runs; throws in words without the live switch, or when a setting is missing or wrong. */
86
+ export async function createProvider({ env = process.env, Boxd, daemonPath, timeouts } = {}) {
87
+ live(env);
88
+ return create({ ...settingsFromEnv(env), ...(Boxd ? { Boxd } : {}), ...(daemonPath === undefined ? {} : { daemonPath }), ...(timeouts ? { timeouts } : {}), maxLifetimeMs: CONFORMANCE_MAX_LIFETIME_MS });
89
+ }
90
+ /**
91
+ * The boxd host the live sweep (sweep.ts) lists and deletes through, from the same settings; it needs no live switch,
92
+ * since the sweep makes nothing, and it calls nothing until the sweep does.
93
+ */
94
+ export async function createHost({ env = process.env, Boxd } = {}) {
95
+ return (await create({ ...settingsFromEnv(env), ...(Boxd ? { Boxd } : {}) })).host;
96
+ }
97
+ /**
98
+ * Where the sweep lists, in words: the org and region the settings name, under the key named by its sha256 prefix alone.
99
+ * A before file listed with another key, org or region would make every computer there read as new, so the sweep
100
+ * refuses it.
101
+ */
102
+ export function sweepScope({ env = process.env } = {}) {
103
+ const { apiKey, org, region } = settingsFromEnv(env);
104
+ const key = createHash("sha256").update(apiKey, "utf8").digest("hex").slice(0, 12);
105
+ return `the boxd org ${org ?? "of the key"} in the region ${region ?? "home"}, with the key sha256:${key}`;
106
+ }
107
+ /** The same provider uploading a daemon that reports version <version>-drift, for the drift.version case. */
108
+ export async function createDriftedProvider({ env = process.env, Boxd, timeouts, buildDaemon = (version) => buildDriftDaemon("amd64", version) } = {}) {
109
+ live(env);
110
+ const settings = settingsFromEnv(env);
111
+ const daemonPath = await buildDaemon(DRIFT_VERSION);
112
+ return create({ ...settings, ...(Boxd ? { Boxd } : {}), ...(timeouts ? { timeouts } : {}), daemonPath, maxLifetimeMs: CONFORMANCE_MAX_LIFETIME_MS });
113
+ }
@@ -1,10 +1,8 @@
1
1
  // A program the computer's user runs reaches none of the vendor's own agent, whose ports each provider declares
2
2
  // (capabilities().vendorAgentPorts), and no outside address, sees its own loopback alone, and finds nothing listening in
3
- // its own network but computerd: computerd init --own-network at work. And it can write nothing root runs, nor read the
4
- // labels a provider keeps in the machine.
3
+ // its own network but computerd: computerd init --own-network at work. And it can write nothing root runs.
5
4
  import { DAEMON_IN_COMPUTER, SOCKET_DIR } from "../../drift.js";
6
5
  import { EGRESS_PROXY_SOCKET } from "../../hosted/network.js";
7
- import { LABEL_FILE } from "../../hosted/scripts.js";
8
6
  import { ARCHIL_HELPER, ARCHIL_SYNC_SOCKET } from "../../mount-archil.js";
9
7
  /**
10
8
  * The unix sockets a program of the computer's user may connect to: the computer's own, computerd's, the Archil sync
@@ -178,18 +176,4 @@ export const isolationCases = [
178
176
  await assertRootRunsClosed(t);
179
177
  },
180
178
  },
181
- {
182
- // The label file of a host that keeps no labels is root's alone: absent or unreadable passes, readable fails.
183
- id: "isolation.label-file",
184
- level: "core",
185
- group: "isolation",
186
- needs: ["files"],
187
- async run(t) {
188
- const read = await t.client.call("files.read", { path: LABEL_FILE });
189
- if (read.ok)
190
- return t.assert(false, `the computer's user reads ${LABEL_FILE}, the labels the provider keeps in the machine`);
191
- t.observe(`${LABEL_FILE}, as the computer's user: ${read.error.code}`);
192
- t.refused(read, `files.read of ${LABEL_FILE} as the computer's user`, ["not_found", "denied"]);
193
- },
194
- },
195
179
  ];
@@ -3,9 +3,13 @@
3
3
  // (Core) and one it does declare is refused or applied truthfully (Full), a computer does not run past its deadline,
4
4
  // the janitor ends only the expired, stopped or running, and a takeover releases the run's lower epochs by label (Full).
5
5
  // A create retried with its request id answers the computer the first made, and after release is refused (Full). A
6
- // deleted computer stays gone: no call to it brings it back. prepareImage called twice answers one image and makes it once.
6
+ // deleted computer stays gone: no call to it brings it back. A provider's prepareImage() and its descriptor's flag agree, and
7
+ // prepareImage called twice answers one image and makes it once.
8
+ // A dial host's machine token is its machine's alone, and ends at delete and at backstopAt (Core).
7
9
  import { randomBytes } from "node:crypto";
10
+ import { ATTACH_CLOSE } from "../../attach.js";
8
11
  import { BACKSTOP_MARGIN_MS } from "../../host.js";
12
+ import { descriptorOf } from "../../providers.js";
9
13
  import { releaseOlder, sweep } from "../../janitor.js";
10
14
  import { EPOCH_LABEL, OWNER_LABEL, RUN_LABEL, runLabels } from "../../labels.js";
11
15
  import { computerNameFor, runLifetimeMs } from "../../provider.js";
@@ -53,8 +57,6 @@ async function refusedCreate(t, spec, what) {
53
57
  /** The deadline case's lifetime, and how much of it must be left once create returns: to connect and start a process. */
54
58
  const DEADLINE_LIFETIME_MS = 45_000;
55
59
  const DEADLINE_LEFT_MS = 15_000;
56
- /** How far a backstop host's vendor timer may read from the request's backstopAt: a timer kept in whole minutes rounds. */
57
- const BACKSTOP_SKEW_MS = 60_000;
58
60
  const seconds = (ms) => Math.round(ms / 100) / 10;
59
61
  /**
60
62
  * A computer for the deadline case, the lifetime it was made with, and when create returned, on the run's clock. A
@@ -244,18 +246,22 @@ export const providerCases = [
244
246
  t.assert(deadline >= before + lifetimeMs - 1000 && deadline <= after + lifetimeMs + 1000, `its deadline, ${String(info.deadline)}, is lifetimeMs after create`);
245
247
  t.deepEqual(await names(t, { ...labels, role: "other" }), [], "list by a label no computer has");
246
248
  }),
247
- // prepareImage twice in one run (spec/computer/provider.md, "prepareImage"): both answer the same image, and the second
248
- // finds the one the first made by its name, so it is told no onWait. A server calls it before its first create, so one
249
- // that builds every time costs every server minutes. A provider with none passes, observed. Core: the first call costs
250
- // at most a build per account and recipe, which the account's first create pays anyway.
249
+ // prepareImage is declared by the provider's method; its descriptor's flag says the same to Settings, which reads it
250
+ // without loading the provider's module. The two agree: a server never skips a provider's image, nor asks one it has
251
+ // not got. A provider on the machine-host adapter has its host's descriptor; another, the registry's for its id.
252
+ // Then prepareImage twice in one run (spec/computer/provider.md, "prepareImage"): both answer the same image, and the
253
+ // second finds the one the first made by its name, so it is told no onWait. A server calls it before its first create,
254
+ // so one that builds every time costs every server minutes. A provider with none passes, observed. Core: the first
255
+ // call costs at most a build per account and recipe, which the account's first create pays anyway.
251
256
  provider("prepare-image", async (t) => {
252
- // A provider on the machine-host adapter: its host's descriptor, the whole one in-tree hosts hand it.
253
- const descriptor = t.provider.host?.descriptor;
257
+ const descriptor = t.provider.host?.descriptor ?? descriptorOf(t.provider.id);
254
258
  const prepare = t.provider.prepareImage?.bind(t.provider);
255
- if (prepare === undefined) {
256
- t.assert(descriptor?.prepareImage !== true, `${descriptor?.label}'s descriptor declares prepareImage, but its provider has no prepareImage(): give the provider class one`);
259
+ if (descriptor !== undefined)
260
+ t.assert((prepare !== undefined) === (descriptor.prepareImage === true), prepare !== undefined
261
+ ? `${descriptor.label}'s provider has prepareImage() but its descriptor does not declare prepareImage: Settings never calls it`
262
+ : `${descriptor.label}'s descriptor declares prepareImage, but its provider has no prepareImage(): give the provider class one`);
263
+ if (prepare === undefined)
257
264
  return t.observe("the provider has no prepareImage(): its computers start from an image a spec names");
258
- }
259
265
  const call = async (which) => {
260
266
  const told = [];
261
267
  const image = t.ok(await prepare({ signal: t.signal, onWait: (making, tag) => told.push(`${making} ${tag}`) }), `the ${which} prepareImage`);
@@ -370,6 +376,30 @@ export const providerCases = [
370
376
  t.ok(await t.provider.release(ref, "delete"), "release delete of the agent's computer");
371
377
  t.deepEqual(await names(t, labels), [], "listed after delete");
372
378
  }, { level: "full", needs: ["persistence", "files"] }),
379
+ // A machine that dials holds a token of its own (spec/computer/attach.md, Hosted machines that dial): good for that
380
+ // machine's hello alone, refused past its backstop and after its delete; and a server no machine can reach makes none.
381
+ provider("dial-token", async (t) => {
382
+ if (t.provider.host?.facts?.connect !== "dial")
383
+ return t.observe("the provider's machines do not dial the server, so they hold no machine token");
384
+ const kit = await t.dial();
385
+ const bare = kit.unreachable();
386
+ const refused = t.refused(await t.attempt(t.spec({ labels: own(t, "dial-token") }), bare.provider), "create on a server with no public address", ["refused"]);
387
+ t.match(refused.message, /public https address/, "create on a server with no public address: the refusal");
388
+ t.equal(bare.creates(), 0, "the vendor's creates asked for by a create on a server with no public address");
389
+ const ref = await t.create({ labels: own(t, "dial-token") });
390
+ const { hello } = await t.connect(ref);
391
+ const token = t.present(kit.token(ref), `the token ${ref.name}'s machine was given`);
392
+ t.equal(await kit.check(token, new Date()), ref.name, "the machine's token, now");
393
+ // Past the machine's backstop: create's time, the most it may live and the margin, and a minute.
394
+ const past = new Date(Date.now() + t.provider.capabilities().maxLifetimeMs + BACKSTOP_MARGIN_MS + 60_000);
395
+ t.equal(await kit.check(token, past), undefined, "the machine's token past its backstop");
396
+ const others = [{ kind: hello.kind === "linux" ? "desktop" : "linux" }, { os: hello.os === "linux" ? "windows" : "linux" }, { arch: hello.arch === "amd64" ? "arm64" : "amd64" }];
397
+ for (const other of others) {
398
+ t.equal(await kit.dialAs(token, { ...hello, ...other }), ATTACH_CLOSE.mismatch, `the machine's token with a hello of ${JSON.stringify(other)}: the close code`);
399
+ }
400
+ t.ok(await t.provider.release(ref, "delete"), "release delete");
401
+ t.equal(await kit.check(token, new Date()), undefined, "the machine's token after its delete");
402
+ }),
373
403
  provider("network-change", async (t) => {
374
404
  const spec = t.spec({ labels: own(t, "network") });
375
405
  const ref = await t.create(spec);
@@ -487,18 +517,4 @@ export const providerCases = [
487
517
  t.ok(await t.provider.release(ref, "delete"), `release ${ref.name}`);
488
518
  t.deepEqual(await names(t, labels), [], "the case's computers after it");
489
519
  }, { level: "full", timeoutMs: 300_000 }),
490
- // A host's backstop claim (facts.backstop, src/host.ts), read back from its vendor on the run's shared computer: get's
491
- // endsAt is the request's backstopAt, which create made from the clock reading its deadline label was made from. A
492
- // provider not on the machine-host adapter, or a host that claims none, has nothing to read back.
493
- provider("backstop", async (t) => {
494
- const host = t.provider.host;
495
- if (host?.facts?.backstop !== true)
496
- return t.observe(host === undefined ? "not on the machine-host adapter: no backstop to read back" : "its host claims no backstop (facts.backstop): nothing to read back");
497
- const listed = t.ok(await t.provider.list(t.runLabels), "list");
498
- const deadline = t.present(listed.find((info) => info.ref.name === t.ref.name)?.deadline, `${t.ref.name}'s deadline, listed`);
499
- const backstopAt = deadline.getTime() - runLifetimeMs(t.spec()) + t.provider.capabilities().maxLifetimeMs + BACKSTOP_MARGIN_MS;
500
- const endsAt = (await host.get(t.ref.id, { timeoutMs: t.patience, signal: t.signal }))?.endsAt;
501
- const reads = endsAt instanceof Date ? endsAt.toISOString() : "none";
502
- t.assert(endsAt instanceof Date && Math.abs(endsAt.getTime() - backstopAt) <= BACKSTOP_SKEW_MS, `${host.descriptor.label} claims backstop (facts.backstop), but its vendor timer reads ${reads}, not ${new Date(backstopAt).toISOString()}, the request's backstopAt (within ${BACKSTOP_SKEW_MS / 1000} s): set it from req.backstopAt at create, and read it back as Machine.endsAt`);
503
- }, { computer: "shared" }),
504
520
  ];
@@ -227,7 +227,7 @@ export function plantSecrets(names) {
227
227
  * register its image, so it is given the run's signal), and conformanceNotes, strings for the report.
228
228
  */
229
229
  async function load(label, module, options, { imageNamed, signal }, declared) {
230
- const { createProvider, createDriftedProvider, conformanceImage, mountFor } = module;
230
+ const { createProvider, createDriftedProvider, conformanceImage, mountFor, dialKit } = module;
231
231
  if (typeof createProvider !== "function")
232
232
  throw new Usage(`${label} does not export createProvider() or create()`);
233
233
  const provider = (await createProvider(options));
@@ -253,6 +253,8 @@ async function load(label, module, options, { imageNamed, signal }, declared) {
253
253
  }
254
254
  if (typeof mountFor === "function")
255
255
  target.mountFor = (kind) => mountFor(kind, options);
256
+ if (typeof dialKit === "function")
257
+ target.dial = () => dialKit(options);
256
258
  if (conformanceImage !== undefined && !imageNamed) {
257
259
  const image = typeof conformanceImage === "function" ? await conformanceImage(options, signal ? { signal } : {}) : undefined;
258
260
  if (typeof image !== "string" || image === "")
@@ -351,6 +353,7 @@ export async function main(argv, io = {}) {
351
353
  ...(target.declared ? { declared: target.declared } : {}),
352
354
  ...(target.planted ? { planted: target.planted } : {}),
353
355
  ...(target.mountFor ? { mountFor: target.mountFor } : {}),
356
+ ...(target.dial ? { dial: target.dial } : {}),
354
357
  ...(onResult ? { onResult } : {}),
355
358
  ...(io.cdp ? { cdp: io.cdp } : {}),
356
359
  });
@@ -0,0 +1,42 @@
1
+ import { type CloudflareProvider } from "../cloudflare.js";
2
+ import type { MachineHost } from "../host.js";
3
+ import type { HostedDial } from "../hosted/provider.js";
4
+ import type { ProviderNote } from "../mount-archil.js";
5
+ /** The environment this module reads, by name, each for the option its comment names. */
6
+ export declare const ENV: {
7
+ /** relayUrl, required: the relay Worker's https address. */
8
+ readonly url: "COMPUTER_CLOUDFLARE_RELAY_URL";
9
+ /** relayToken, required: the relay's RELAY_TOKEN. */
10
+ readonly token: "COMPUTER_CLOUDFLARE_RELAY_TOKEN";
11
+ };
12
+ /** The longest lifetime a computer of a run may ask for: init's deadline and the janitor end each container by then. */
13
+ export declare const CONFORMANCE_MAX_LIFETIME_MS: number;
14
+ /** The provider's options this module reads from env; throws in words without either, never echoing the token. */
15
+ export declare function settingsFromEnv(env?: Record<string, string | undefined>): {
16
+ relayUrl: string;
17
+ relayToken: string;
18
+ };
19
+ export interface CloudflareModuleOptions {
20
+ /** The environment to read; process.env by default. */
21
+ env?: Record<string, string | undefined>;
22
+ /** The server the containers dial: dial-conformance.mjs gives its own. Without it every create is refused in words. */
23
+ dial?: HostedDial;
24
+ /** The daemon the server serves (its sha256 is what a container checks); default this package's dist/computerd-linux-amd64. */
25
+ daemonPath?: string;
26
+ /** The fetch the relay's calls go through; default the global one. */
27
+ fetch?: typeof fetch;
28
+ /** What the provider says that is no failure: the CLI gives it and puts it in the report. */
29
+ onNote?: ProviderNote;
30
+ }
31
+ /** The provider the run makes computers with, dialing the server options.dial names. */
32
+ export declare function createProvider({ env, dial, daemonPath, fetch, onNote }?: CloudflareModuleOptions): CloudflareProvider;
33
+ /** The run's image: the box image the relay was deployed FROM, as its /v1/health names it. */
34
+ export declare function conformanceImage(options?: Pick<CloudflareModuleOptions, "env" | "fetch">, context?: {
35
+ signal?: AbortSignal;
36
+ }): Promise<string>;
37
+ /** The server the run's containers dial, as the CLI asks for it: refused in words (dial-only.ts). */
38
+ export declare const dialKit: () => import("./types.js").DialKit;
39
+ /** The Cloudflare host the live sweep lists and deletes through, from the same settings; it makes nothing. */
40
+ export declare function createHost({ env, fetch }?: Pick<CloudflareModuleOptions, "env" | "fetch">): MachineHost;
41
+ /** Where the sweep lists, in words: the relay the settings name. */
42
+ export declare function sweepScope({ env }?: Pick<CloudflareModuleOptions, "env">): string;
@@ -0,0 +1,54 @@
1
+ // Cloudflare for the conformance run. Its containers dial the server that minted their tokens (facts.connect "dial"), so
2
+ // a Core run happens inside that server's own process, behind its public address: serve's
3
+ // packages/serve/scripts/dial-conformance.mjs --provider cloudflare gives createProvider() its dial and the run a DialKit.
4
+ // From a laptop's CLI, dialKit() refuses in words, and the provider refuses every create before the relay is called.
5
+ //
6
+ // The provider reads no environment: this module reads its own COMPUTER_CLOUDFLARE_* names and passes each to create()
7
+ // as its option. The live sweep (sweep.ts, --provider cloudflare) reads the same names through createHost.
8
+ import { create } from "../cloudflare.js";
9
+ import { dialOnlyFromServer } from "./dial-only.js";
10
+ /** The environment this module reads, by name, each for the option its comment names. */
11
+ export const ENV = {
12
+ /** relayUrl, required: the relay Worker's https address. */
13
+ url: "COMPUTER_CLOUDFLARE_RELAY_URL",
14
+ /** relayToken, required: the relay's RELAY_TOKEN. */
15
+ token: "COMPUTER_CLOUDFLARE_RELAY_TOKEN",
16
+ };
17
+ /** The longest lifetime a computer of a run may ask for: init's deadline and the janitor end each container by then. */
18
+ export const CONFORMANCE_MAX_LIFETIME_MS = 30 * 60_000;
19
+ /** The provider's options this module reads from env; throws in words without either, never echoing the token. */
20
+ export function settingsFromEnv(env = process.env) {
21
+ const relayUrl = env[ENV.url];
22
+ const relayToken = env[ENV.token];
23
+ if (!relayUrl || !relayToken)
24
+ throw new Error(`the Cloudflare conformance module needs ${ENV.url} and ${ENV.token}`);
25
+ return { relayUrl, relayToken };
26
+ }
27
+ /** The provider the run makes computers with, dialing the server options.dial names. */
28
+ export function createProvider({ env = process.env, dial, daemonPath, fetch, onNote } = {}) {
29
+ return create({
30
+ ...settingsFromEnv(env),
31
+ ...(dial ? { dial } : {}),
32
+ ...(daemonPath === undefined ? {} : { daemonPath }),
33
+ ...(fetch ? { fetch } : {}),
34
+ ...(onNote ? { onNote } : {}),
35
+ maxLifetimeMs: CONFORMANCE_MAX_LIFETIME_MS,
36
+ });
37
+ }
38
+ /** The run's image: the box image the relay was deployed FROM, as its /v1/health names it. */
39
+ export async function conformanceImage(options = {}, context = {}) {
40
+ const image = await createProvider(options).prepareImage(context);
41
+ if (!image.ok)
42
+ throw new Error(image.error.message);
43
+ return image.value;
44
+ }
45
+ /** The server the run's containers dial, as the CLI asks for it: refused in words (dial-only.ts). */
46
+ export const dialKit = dialOnlyFromServer("cloudflare", "Cloudflare");
47
+ /** The Cloudflare host the live sweep lists and deletes through, from the same settings; it makes nothing. */
48
+ export function createHost({ env = process.env, fetch } = {}) {
49
+ return create({ ...settingsFromEnv(env), ...(fetch ? { fetch } : {}) }).host;
50
+ }
51
+ /** Where the sweep lists, in words: the relay the settings name. */
52
+ export function sweepScope({ env = process.env } = {}) {
53
+ return `the Cloudflare relay at ${settingsFromEnv(env).relayUrl}`;
54
+ }
@@ -1,5 +1,10 @@
1
1
  import { type DaytonaProvider, type DaytonaProviderOptions } from "../daytona.js";
2
2
  import type { MachineHost } from "../host.js";
3
+ import type { MountKind } from "../mount.js";
4
+ import { type ArchilRunFolderOptions } from "./archil.js";
5
+ import type { RunFolder } from "./types.js";
6
+ /** The Archil disk's settings for the mount cases, by name (COMPUTER_ARCHIL_*: all five, or none). */
7
+ export { ARCHIL_ENV } from "./archil.js";
3
8
  /** The environment this module reads, by name, each for the option its comment names. */
4
9
  export declare const DAYTONA_ENV: {
5
10
  /** apiKey, required: the Daytona API key. */
@@ -20,6 +25,11 @@ export declare const DAYTONA_ENV: {
20
25
  readonly snapshot: "COMPUTER_DAYTONA_SNAPSHOT";
21
26
  /** gpuSnapshot: the GPU snapshot of box/Dockerfile GPU computers are made from (box/build-daytona.py --gpu); default daytona-gpu. */
22
27
  readonly gpuSnapshot: "COMPUTER_DAYTONA_GPU_SNAPSHOT";
28
+ /**
29
+ * archilEgress: a self-hosted Daytona target's Archil egress relay, <IPv4 gateway>:<mount lane>:<data lane>. Set, the
30
+ * provider takes an Archil mount; unset, it refuses one (Archil's client hangs on Daytona's hosted cloud).
31
+ */
32
+ readonly archilEgress: "COMPUTER_DAYTONA_ARCHIL_EGRESS";
23
33
  };
24
34
  /** The names this module reads, under the conformance modules' common name (ConformanceModule.ENV). */
25
35
  export declare const ENV: {
@@ -41,6 +51,11 @@ export declare const ENV: {
41
51
  readonly snapshot: "COMPUTER_DAYTONA_SNAPSHOT";
42
52
  /** gpuSnapshot: the GPU snapshot of box/Dockerfile GPU computers are made from (box/build-daytona.py --gpu); default daytona-gpu. */
43
53
  readonly gpuSnapshot: "COMPUTER_DAYTONA_GPU_SNAPSHOT";
54
+ /**
55
+ * archilEgress: a self-hosted Daytona target's Archil egress relay, <IPv4 gateway>:<mount lane>:<data lane>. Set, the
56
+ * provider takes an Archil mount; unset, it refuses one (Archil's client hangs on Daytona's hosted cloud).
57
+ */
58
+ readonly archilEgress: "COMPUTER_DAYTONA_ARCHIL_EGRESS";
44
59
  };
45
60
  /**
46
61
  * The provider's options this module reads from env, each only when its name is set; throws in words without the key,
@@ -65,6 +80,16 @@ export interface DaytonaModuleOptions {
65
80
  }
66
81
  /** The image every computer of the run starts from: COMPUTER_DAYTONA_SNAPSHOT, or Daytona's default snapshot. */
67
82
  export declare function conformanceImage({ env }?: Pick<DaytonaModuleOptions, "env">): string;
83
+ /**
84
+ * A fresh run folder for the mount cases: an Archil one on the disk the COMPUTER_ARCHIL_* settings name (the shared
85
+ * archilRunFolder; the run's snapshot is then one of box/Dockerfile, and COMPUTER_DAYTONA_USER is 2510:2510), only where
86
+ * COMPUTER_DAYTONA_ARCHIL_EGRESS names the target's relay, since the provider takes an Archil mount only then; none
87
+ * otherwise, and none for a bind, which a remote computer cannot take.
88
+ */
89
+ export declare function mountFor(kind: MountKind, { env, archil }?: {
90
+ env?: Record<string, string | undefined>;
91
+ archil?: Pick<ArchilRunFolderOptions, "objects" | "Archil" | "baseUrl">;
92
+ }): Promise<RunFolder | undefined>;
68
93
  /** The provider the CLI runs; throws in words when a setting is missing or wrong. */
69
94
  export declare function createProvider(options?: DaytonaModuleOptions): DaytonaProvider;
70
95
  /**
@@ -3,10 +3,15 @@
3
3
  // another organization's key on a host that runs other Daytona work) and passes each to create() as its option, the key
4
4
  // read only when createProvider() runs. Every sandbox of a run has a bounded life besides its TTL: Daytona stops one
5
5
  // after 30 minutes with no outside activity and deletes it as soon as it stops (see conformanceNotes). The live sweep
6
- // (sweep.ts, --provider daytona) reads the same names through createHost: it makes nothing.
6
+ // (sweep.ts, --provider daytona) reads the same names through createHost: it makes nothing. The mount cases run on a
7
+ // self-hosted Daytona target alone: COMPUTER_DAYTONA_ARCHIL_EGRESS names its Archil egress relay, and the
8
+ // COMPUTER_ARCHIL_* settings the disk (mountFor).
7
9
  import { create } from "../daytona.js";
8
10
  import { DAYTONA_DEFAULT_SNAPSHOT } from "../descriptors/daytona.js";
11
+ import { archilRunFolder, archilSettings } from "./archil.js";
9
12
  import { buildDriftDaemon, DRIFT_VERSION } from "./drift-daemon.js";
13
+ /** The Archil disk's settings for the mount cases, by name (COMPUTER_ARCHIL_*: all five, or none). */
14
+ export { ARCHIL_ENV } from "./archil.js";
10
15
  /** The environment this module reads, by name, each for the option its comment names. */
11
16
  export const DAYTONA_ENV = {
12
17
  /** apiKey, required: the Daytona API key. */
@@ -27,6 +32,11 @@ export const DAYTONA_ENV = {
27
32
  snapshot: "COMPUTER_DAYTONA_SNAPSHOT",
28
33
  /** gpuSnapshot: the GPU snapshot of box/Dockerfile GPU computers are made from (box/build-daytona.py --gpu); default daytona-gpu. */
29
34
  gpuSnapshot: "COMPUTER_DAYTONA_GPU_SNAPSHOT",
35
+ /**
36
+ * archilEgress: a self-hosted Daytona target's Archil egress relay, <IPv4 gateway>:<mount lane>:<data lane>. Set, the
37
+ * provider takes an Archil mount; unset, it refuses one (Archil's client hangs on Daytona's hosted cloud).
38
+ */
39
+ archilEgress: "COMPUTER_DAYTONA_ARCHIL_EGRESS",
30
40
  };
31
41
  /** The names this module reads, under the conformance modules' common name (ConformanceModule.ENV). */
32
42
  export const ENV = DAYTONA_ENV;
@@ -46,6 +56,7 @@ export function settingsFromEnv(env = process.env) {
46
56
  const sandboxClass = named(DAYTONA_ENV.sandboxClass);
47
57
  const user = named(DAYTONA_ENV.user);
48
58
  const gpuSnapshot = named(DAYTONA_ENV.gpuSnapshot);
59
+ const archilEgress = named(DAYTONA_ENV.archilEgress);
49
60
  return {
50
61
  apiKey,
51
62
  ...(url ? { apiUrl: url.value } : {}),
@@ -58,6 +69,8 @@ export function settingsFromEnv(env = process.env) {
58
69
  ...(user ? { daemonUser: user.value } : {}),
59
70
  // create() refuses a name that is not one of ours in words.
60
71
  ...(gpuSnapshot ? { gpuSnapshot: gpuSnapshot.value } : {}),
72
+ // create() refuses one of another shape in words.
73
+ ...(archilEgress ? { archilEgress: archilEgress.value } : {}),
61
74
  };
62
75
  }
63
76
  /** Minutes without outside activity before Daytona stops a run's sandbox: at most 30, so none outlives a run for long. */
@@ -84,6 +97,18 @@ function optionsOf({ env = process.env, fetch, webSocket, timeouts, onNote }) {
84
97
  export function conformanceImage({ env = process.env } = {}) {
85
98
  return env[DAYTONA_ENV.snapshot] || DAYTONA_DEFAULT_SNAPSHOT;
86
99
  }
100
+ /**
101
+ * A fresh run folder for the mount cases: an Archil one on the disk the COMPUTER_ARCHIL_* settings name (the shared
102
+ * archilRunFolder; the run's snapshot is then one of box/Dockerfile, and COMPUTER_DAYTONA_USER is 2510:2510), only where
103
+ * COMPUTER_DAYTONA_ARCHIL_EGRESS names the target's relay, since the provider takes an Archil mount only then; none
104
+ * otherwise, and none for a bind, which a remote computer cannot take.
105
+ */
106
+ export async function mountFor(kind, { env = process.env, archil = {} } = {}) {
107
+ if (kind !== "archil" || !env[DAYTONA_ENV.archilEgress])
108
+ return undefined;
109
+ const settings = archilSettings(env);
110
+ return settings === undefined ? undefined : archilRunFolder({ ...settings, ...archil });
111
+ }
87
112
  /** The provider the CLI runs; throws in words when a setting is missing or wrong. */
88
113
  export function createProvider(options = {}) {
89
114
  return create(optionsOf(options));
@@ -0,0 +1,6 @@
1
+ import type { DialKit } from "./types.js";
2
+ /**
3
+ * The dialKit() of a dial host's module, by its provider id and label: it always refuses, naming the script to run, and
4
+ * the setting that makes the provider dial when dialing is not its only way (E2B's and Modal's COMPUTER_<ID>_CONNECT=dial).
5
+ */
6
+ export declare function dialOnlyFromServer(id: string, label: string, setting?: string): () => DialKit;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The dialKit() of a dial host's module, by its provider id and label: it always refuses, naming the script to run, and
3
+ * the setting that makes the provider dial when dialing is not its only way (E2B's and Modal's COMPUTER_<ID>_CONNECT=dial).
4
+ */
5
+ export function dialOnlyFromServer(id, label, setting) {
6
+ return () => {
7
+ throw new Error(`${label}'s machines dial the server that minted their tokens, and this run has no public server: run its Core with packages/serve/scripts/dial-conformance.mjs --provider ${id}${setting ? ` with ${setting}` : ""} inside a server the internet reaches at AGENTRUN_PUBLIC_URL`);
8
+ };
9
+ }