@parcha/agentrun-computer 0.0.0-stage → 0.1.0-beta.32

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 (173) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +8 -0
  3. package/README.md +2401 -2
  4. package/box/Dockerfile +69 -0
  5. package/box/agentrun-archil +168 -0
  6. package/box/build-daytona.py +26 -0
  7. package/box/build-e2b.mjs +32 -0
  8. package/box/build-modal.py +17 -0
  9. package/dist/actions.d.ts +18 -0
  10. package/dist/actions.js +139 -0
  11. package/dist/browser.d.ts +151 -0
  12. package/dist/browser.js +305 -0
  13. package/dist/browserbase.d.ts +139 -0
  14. package/dist/browserbase.js +408 -0
  15. package/dist/child.d.ts +40 -0
  16. package/dist/child.js +127 -0
  17. package/dist/client.d.ts +22 -0
  18. package/dist/client.js +136 -0
  19. package/dist/computerd-linux-amd64 +0 -0
  20. package/dist/computerd-linux-arm64 +0 -0
  21. package/dist/conformance/archil.d.ts +68 -0
  22. package/dist/conformance/archil.js +152 -0
  23. package/dist/conformance/browserbase.d.ts +35 -0
  24. package/dist/conformance/browserbase.js +45 -0
  25. package/dist/conformance/cases/apps.d.ts +2 -0
  26. package/dist/conformance/cases/apps.js +155 -0
  27. package/dist/conformance/cases/browser.d.ts +4 -0
  28. package/dist/conformance/cases/browser.js +105 -0
  29. package/dist/conformance/cases/drift.d.ts +2 -0
  30. package/dist/conformance/cases/drift.js +64 -0
  31. package/dist/conformance/cases/exec.d.ts +2 -0
  32. package/dist/conformance/cases/exec.js +125 -0
  33. package/dist/conformance/cases/files.d.ts +2 -0
  34. package/dist/conformance/cases/files.js +294 -0
  35. package/dist/conformance/cases/health.d.ts +2 -0
  36. package/dist/conformance/cases/health.js +71 -0
  37. package/dist/conformance/cases/index.d.ts +9 -0
  38. package/dist/conformance/cases/index.js +37 -0
  39. package/dist/conformance/cases/input.d.ts +12 -0
  40. package/dist/conformance/cases/input.js +109 -0
  41. package/dist/conformance/cases/isolation.d.ts +21 -0
  42. package/dist/conformance/cases/isolation.js +92 -0
  43. package/dist/conformance/cases/lifetime.d.ts +2 -0
  44. package/dist/conformance/cases/lifetime.js +64 -0
  45. package/dist/conformance/cases/mount.d.ts +2 -0
  46. package/dist/conformance/cases/mount.js +252 -0
  47. package/dist/conformance/cases/process.d.ts +2 -0
  48. package/dist/conformance/cases/process.js +240 -0
  49. package/dist/conformance/cases/provider.d.ts +2 -0
  50. package/dist/conformance/cases/provider.js +302 -0
  51. package/dist/conformance/cases/screen.d.ts +9 -0
  52. package/dist/conformance/cases/screen.js +230 -0
  53. package/dist/conformance/cases/settings.d.ts +57 -0
  54. package/dist/conformance/cases/settings.js +142 -0
  55. package/dist/conformance/cases/touch.d.ts +2 -0
  56. package/dist/conformance/cases/touch.js +117 -0
  57. package/dist/conformance/cases/util.d.ts +7 -0
  58. package/dist/conformance/cases/util.js +8 -0
  59. package/dist/conformance/cdp.d.ts +13 -0
  60. package/dist/conformance/cdp.js +88 -0
  61. package/dist/conformance/cli.d.ts +29 -0
  62. package/dist/conformance/cli.js +231 -0
  63. package/dist/conformance/daytona-sweep.d.ts +18 -0
  64. package/dist/conformance/daytona-sweep.js +118 -0
  65. package/dist/conformance/daytona.d.ts +83 -0
  66. package/dist/conformance/daytona.js +107 -0
  67. package/dist/conformance/docker.d.ts +38 -0
  68. package/dist/conformance/docker.js +70 -0
  69. package/dist/conformance/drift-daemon.d.ts +8 -0
  70. package/dist/conformance/drift-daemon.js +41 -0
  71. package/dist/conformance/e2b-diagnose.d.ts +16 -0
  72. package/dist/conformance/e2b-diagnose.js +61 -0
  73. package/dist/conformance/e2b-sweep.d.ts +18 -0
  74. package/dist/conformance/e2b-sweep.js +125 -0
  75. package/dist/conformance/e2b.d.ts +74 -0
  76. package/dist/conformance/e2b.js +111 -0
  77. package/dist/conformance/fixture.d.ts +65 -0
  78. package/dist/conformance/fixture.js +98 -0
  79. package/dist/conformance/index.d.ts +8 -0
  80. package/dist/conformance/index.js +8 -0
  81. package/dist/conformance/kernel.d.ts +31 -0
  82. package/dist/conformance/kernel.js +40 -0
  83. package/dist/conformance/kind.d.ts +23 -0
  84. package/dist/conformance/kind.js +58 -0
  85. package/dist/conformance/modal-sweep.d.ts +22 -0
  86. package/dist/conformance/modal-sweep.js +190 -0
  87. package/dist/conformance/modal.d.ts +69 -0
  88. package/dist/conformance/modal.js +76 -0
  89. package/dist/conformance/orgo.d.ts +41 -0
  90. package/dist/conformance/orgo.js +69 -0
  91. package/dist/conformance/phone-harness.d.ts +61 -0
  92. package/dist/conformance/phone-harness.js +241 -0
  93. package/dist/conformance/png.d.ts +16 -0
  94. package/dist/conformance/png.js +132 -0
  95. package/dist/conformance/report.d.ts +2 -0
  96. package/dist/conformance/report.js +86 -0
  97. package/dist/conformance/runner.d.ts +11 -0
  98. package/dist/conformance/runner.js +585 -0
  99. package/dist/conformance/tar.d.ts +13 -0
  100. package/dist/conformance/tar.js +105 -0
  101. package/dist/conformance/types.d.ts +257 -0
  102. package/dist/conformance/types.js +24 -0
  103. package/dist/daemon-copy.d.ts +40 -0
  104. package/dist/daemon-copy.js +259 -0
  105. package/dist/daytona.d.ts +178 -0
  106. package/dist/daytona.js +1484 -0
  107. package/dist/desktop.d.ts +24 -0
  108. package/dist/desktop.js +68 -0
  109. package/dist/docker/egress-main.d.ts +1 -0
  110. package/dist/docker/egress-main.js +68 -0
  111. package/dist/docker/egress-proxy.d.ts +53 -0
  112. package/dist/docker/egress-proxy.js +450 -0
  113. package/dist/docker/egress-table.d.ts +39 -0
  114. package/dist/docker/egress-table.js +197 -0
  115. package/dist/docker/egress.d.ts +109 -0
  116. package/dist/docker/egress.js +318 -0
  117. package/dist/docker/image.d.ts +49 -0
  118. package/dist/docker/image.js +302 -0
  119. package/dist/docker/stage.d.ts +21 -0
  120. package/dist/docker/stage.js +290 -0
  121. package/dist/docker/volume.d.ts +24 -0
  122. package/dist/docker/volume.js +67 -0
  123. package/dist/docker.d.ts +150 -0
  124. package/dist/docker.js +1200 -0
  125. package/dist/drift.d.ts +200 -0
  126. package/dist/drift.js +416 -0
  127. package/dist/e2b.d.ts +335 -0
  128. package/dist/e2b.js +1515 -0
  129. package/dist/entry.d.ts +2 -0
  130. package/dist/entry.js +24 -0
  131. package/dist/files.d.ts +50 -0
  132. package/dist/files.js +208 -0
  133. package/dist/index.d.ts +27 -0
  134. package/dist/index.js +26 -0
  135. package/dist/isolation.d.ts +29 -0
  136. package/dist/isolation.js +71 -0
  137. package/dist/janitor.d.ts +50 -0
  138. package/dist/janitor.js +135 -0
  139. package/dist/kernel.d.ts +113 -0
  140. package/dist/kernel.js +358 -0
  141. package/dist/kinds.d.ts +79 -0
  142. package/dist/kinds.js +133 -0
  143. package/dist/labels.d.ts +23 -0
  144. package/dist/labels.js +50 -0
  145. package/dist/modal.d.ts +302 -0
  146. package/dist/modal.js +1374 -0
  147. package/dist/mount-archil.d.ts +164 -0
  148. package/dist/mount-archil.js +471 -0
  149. package/dist/mount.d.ts +57 -0
  150. package/dist/mount.js +104 -0
  151. package/dist/orgo-channel.d.ts +96 -0
  152. package/dist/orgo-channel.js +391 -0
  153. package/dist/orgo.d.ts +139 -0
  154. package/dist/orgo.js +1006 -0
  155. package/dist/phone-harness.d.ts +185 -0
  156. package/dist/phone-harness.js +1420 -0
  157. package/dist/processes.d.ts +24 -0
  158. package/dist/processes.js +40 -0
  159. package/dist/protocol.d.ts +729 -0
  160. package/dist/protocol.js +54 -0
  161. package/dist/provider.d.ts +245 -0
  162. package/dist/provider.js +37 -0
  163. package/dist/providers.d.ts +68 -0
  164. package/dist/providers.js +25 -0
  165. package/dist/result.d.ts +15 -0
  166. package/dist/result.js +2 -0
  167. package/dist/screen-watch.d.ts +150 -0
  168. package/dist/screen-watch.js +490 -0
  169. package/dist/test-connection.d.ts +17 -0
  170. package/dist/test-connection.js +26 -0
  171. package/dist/wait.d.ts +23 -0
  172. package/dist/wait.js +65 -0
  173. package/package.json +62 -4
@@ -0,0 +1,18 @@
1
+ import type { DaytonaProviderOptions } from "../daytona.js";
2
+ /** A stream as main writes to it: done is called once the text is handed on. */
3
+ export interface Writer {
4
+ write(text: string, done?: (error?: Error | null) => void): unknown;
5
+ }
6
+ export interface SweepIo {
7
+ /** Where the settings are read; default process.env. */
8
+ env?: Record<string, string | undefined>;
9
+ fetch?: DaytonaProviderOptions["fetch"];
10
+ webSocket?: DaytonaProviderOptions["webSocket"];
11
+ stdout?: Writer;
12
+ stderr?: Writer;
13
+ /** How long --after reads one deleted sandbox back before it counts as still there; default 60 s. */
14
+ waitMs?: number;
15
+ /** The pause between two reads of one sandbox; default 2 s. */
16
+ pollMs?: number;
17
+ }
18
+ export declare function main(argv: string[], io?: SweepIo): Promise<number>;
@@ -0,0 +1,118 @@
1
+ // The sweep around a live Daytona run, with the conformance module's settings (COMPUTER_DAYTONA_*, never DAYTONA_*):
2
+ //
3
+ // node packages/computer/dist/conformance/daytona-sweep.js --before <file>
4
+ // node packages/computer/dist/conformance/daytona-sweep.js --after <file>
5
+ //
6
+ // --before records the id of every sandbox carrying agentrun.computer=1 into <file>. --after lists them again, deletes
7
+ // (release delete) every one whose id is not in <file>, then reads each of those back with GET /sandbox/{id} until
8
+ // Daytona answers 404, up to 60 s each, and prints one JSON line, {"swept":n,"notFound":m,"stillThere":[ids]}: swept is
9
+ // every sandbox it found that was not there before, and notFound + stillThere.length = swept. A sandbox in <file> is
10
+ // never touched: no call names it. Exit 0 when every swept sandbox reads back 404, 1 when one is still there, 2 on a
11
+ // usage error, a before file it cannot read, a missing key or a listing Daytona refused (nothing is deleted then).
12
+ import { readFileSync, writeFileSync } from "node:fs";
13
+ import { COMPUTER_LABEL } from "../drift.js";
14
+ import { isCommand } from "../entry.js";
15
+ import { waitUntil } from "../wait.js";
16
+ import { createProvider } from "./daytona.js";
17
+ const USAGE = `usage: node packages/computer/dist/conformance/daytona-sweep.js --before <file> | --after <file>
18
+ --before <file> record the id of every sandbox carrying ${COMPUTER_LABEL}=1 into <file>
19
+ --after <file> delete every sandbox carrying ${COMPUTER_LABEL}=1 whose id is not in <file>, read each back until
20
+ Daytona answers 404 (up to 60 s each), and print {"swept":n,"notFound":m,"stillThere":[ids]}
21
+ settings: COMPUTER_DAYTONA_API_KEY (required) and COMPUTER_DAYTONA_API_URL, as the conformance module reads them
22
+ exit: 0 every swept sandbox is gone, 1 one is still there, 2 usage error, unreadable before file, no key, or a refused listing`;
23
+ class Usage extends Error {
24
+ }
25
+ const write = (stream, text) => new Promise((resolve) => void stream.write(text, () => resolve()));
26
+ function parse(argv) {
27
+ let found;
28
+ for (let i = 0; i < argv.length; i++) {
29
+ const [flag = "", inline] = (argv[i] ?? "").split(/=(.*)/s, 2);
30
+ if (flag !== "--before" && flag !== "--after")
31
+ throw new Usage(`unknown option ${flag}`);
32
+ const file = inline ?? argv[++i];
33
+ if (file === undefined || file === "" || file.startsWith("--"))
34
+ throw new Usage(`${flag} needs a file`);
35
+ if (found !== undefined)
36
+ throw new Usage("give --before <file> or --after <file>, one of them");
37
+ found = { mode: flag === "--before" ? "before" : "after", file };
38
+ }
39
+ if (found === undefined)
40
+ throw new Usage("give --before <file> or --after <file>, one of them");
41
+ return found;
42
+ }
43
+ /** The ids a before file holds, or why it is not one. */
44
+ function beforeIds(file) {
45
+ let text;
46
+ try {
47
+ text = readFileSync(file, "utf8");
48
+ }
49
+ catch (error) {
50
+ throw new Usage(`cannot read the before file ${file}: ${error.message}`);
51
+ }
52
+ let record;
53
+ try {
54
+ record = JSON.parse(text);
55
+ }
56
+ catch {
57
+ record = undefined;
58
+ }
59
+ const ids = record?.ids;
60
+ if (!Array.isArray(ids) || !ids.every((id) => typeof id === "string" && id !== ""))
61
+ throw new Usage(`${file} is not a before file: it holds no "ids" array of sandbox ids`);
62
+ return new Set(ids);
63
+ }
64
+ export async function main(argv, io = {}) {
65
+ const { env = process.env, stdout = process.stdout, stderr = process.stderr, waitMs = 60_000, pollMs = 2_000 } = io;
66
+ let args;
67
+ let before;
68
+ let provider;
69
+ try {
70
+ args = parse(argv);
71
+ if (args.mode === "after")
72
+ before = beforeIds(args.file);
73
+ // A release waits for the sandbox to go, for as long as the sweep's own wait.
74
+ provider = createProvider({ env, timeouts: { goneMs: waitMs, pollMs }, ...(io.fetch ? { fetch: io.fetch } : {}), ...(io.webSocket ? { webSocket: io.webSocket } : {}) });
75
+ }
76
+ catch (error) {
77
+ await write(stderr, `${error.message}\n${error instanceof Usage ? `${USAGE}\n` : ""}`);
78
+ return 2;
79
+ }
80
+ const listed = await provider.listLabelled();
81
+ if (!listed.ok) {
82
+ await write(stderr, `listing the sandboxes carrying ${COMPUTER_LABEL}=1 failed, so nothing was ${args.mode === "after" ? "deleted" : "recorded"}: ${listed.error.message}\n`);
83
+ return 2;
84
+ }
85
+ if (before === undefined) {
86
+ const ids = [...new Set(listed.value.map((sb) => sb.id))].sort();
87
+ writeFileSync(args.file, `${JSON.stringify({ label: `${COMPUTER_LABEL}=1`, at: new Date().toISOString(), ids }, null, 2)}\n`);
88
+ await write(stdout, `${JSON.stringify({ recorded: ids.length, file: args.file })}\n`);
89
+ return 0;
90
+ }
91
+ const known = before;
92
+ const fresh = [...new Map(listed.value.filter((sb) => !known.has(sb.id)).map((sb) => [sb.id, sb])).values()];
93
+ for (const sb of fresh) {
94
+ const released = await provider.release({ id: sb.id, name: sb.name ?? "" }, "delete");
95
+ if (!released.ok)
96
+ await write(stderr, `${sb.id} (${sb.name ?? "no name"}) was not deleted: ${released.error.message}\n`);
97
+ }
98
+ // Each one read back on its own, at once, through waitUntil: a 404 is gone; anything else, or no answer, is read
99
+ // again every pollMs until its wait ends.
100
+ const gone = await Promise.all(fresh.map(async (sb) => {
101
+ const waited = await waitUntil(() => provider.probe(sb.id), (read) => read.ok && read.value.status === 404, {
102
+ boundMs: waitMs,
103
+ minMs: pollMs,
104
+ maxMs: pollMs,
105
+ what: `${sb.id} to be gone`,
106
+ describe: (read) => `GET /sandbox/${sb.id} answered ${read.ok ? `${read.value.status}${read.value.state ? ` (${read.value.state})` : ""}` : read.error.message}`,
107
+ });
108
+ if (!waited.ok)
109
+ await write(stderr, `${sb.id} is still there: ${waited.error.message}\n`);
110
+ return waited.ok;
111
+ }));
112
+ const stillThere = fresh.filter((_, i) => !gone[i]).map((sb) => sb.id);
113
+ await write(stdout, `${JSON.stringify({ swept: fresh.length, notFound: fresh.length - stillThere.length, stillThere })}\n`);
114
+ return stillThere.length === 0 ? 0 : 1;
115
+ }
116
+ if (isCommand(import.meta)) {
117
+ process.exitCode = await main(process.argv.slice(2));
118
+ }
@@ -0,0 +1,83 @@
1
+ import { type DaytonaCreateOptions, type DaytonaProvider, type DaytonaProviderOptions } from "../daytona.js";
2
+ import type { MountKind } from "../mount.js";
3
+ import { type ArchilRunFolderOptions } from "./archil.js";
4
+ import type { RunFolder } from "./types.js";
5
+ /** The Archil disk's settings for the mount cases, by name (COMPUTER_ARCHIL_*: all five, or none). */
6
+ export { ARCHIL_ENV } from "./archil.js";
7
+ /**
8
+ * A fresh run folder for the mount cases: an Archil one on the disk the COMPUTER_ARCHIL_* settings name (the shared
9
+ * archilRunFolder; the run's snapshot is then one of box/Dockerfile, and COMPUTER_DAYTONA_USER is 2510:2510); none when
10
+ * they name none, and none for a bind, which a remote computer cannot take.
11
+ */
12
+ export declare function mountFor(kind: MountKind, { env, archil }?: {
13
+ env?: Record<string, string | undefined>;
14
+ archil?: Pick<ArchilRunFolderOptions, "objects" | "Archil" | "baseUrl">;
15
+ }): Promise<RunFolder | undefined>;
16
+ /** The environment this module reads, by name, each for the option its comment names. */
17
+ export declare const DAYTONA_ENV: {
18
+ /** apiKey, required: the Daytona API key. */
19
+ readonly key: "COMPUTER_DAYTONA_API_KEY";
20
+ /** apiUrl; default https://app.daytona.io/api. */
21
+ readonly url: "COMPUTER_DAYTONA_API_URL";
22
+ /** daemonPath; default this package's dist/computerd-linux-<arch>. */
23
+ readonly daemon: "COMPUTER_DAYTONA_DAEMON";
24
+ /** arch: amd64 (default) or arm64, the sandboxes' architecture. */
25
+ readonly arch: "COMPUTER_DAYTONA_ARCH";
26
+ /** target: the Daytona target (region); default the organization's. */
27
+ readonly target: "COMPUTER_DAYTONA_TARGET";
28
+ /** sandboxClass: container (default) or linux-vm, the class the snapshot makes. */
29
+ readonly sandboxClass: "COMPUTER_DAYTONA_CLASS";
30
+ /** daemonUser: uid:gid the daemon runs as; default 2510:2510. */
31
+ readonly user: "COMPUTER_DAYTONA_USER";
32
+ /** The snapshot every computer of the run starts from; default "default", Daytona's default snapshot. */
33
+ readonly snapshot: "COMPUTER_DAYTONA_SNAPSHOT";
34
+ };
35
+ /** The names this module reads, under the conformance modules' common name (ConformanceModule.ENV). */
36
+ export declare const ENV: {
37
+ /** apiKey, required: the Daytona API key. */
38
+ readonly key: "COMPUTER_DAYTONA_API_KEY";
39
+ /** apiUrl; default https://app.daytona.io/api. */
40
+ readonly url: "COMPUTER_DAYTONA_API_URL";
41
+ /** daemonPath; default this package's dist/computerd-linux-<arch>. */
42
+ readonly daemon: "COMPUTER_DAYTONA_DAEMON";
43
+ /** arch: amd64 (default) or arm64, the sandboxes' architecture. */
44
+ readonly arch: "COMPUTER_DAYTONA_ARCH";
45
+ /** target: the Daytona target (region); default the organization's. */
46
+ readonly target: "COMPUTER_DAYTONA_TARGET";
47
+ /** sandboxClass: container (default) or linux-vm, the class the snapshot makes. */
48
+ readonly sandboxClass: "COMPUTER_DAYTONA_CLASS";
49
+ /** daemonUser: uid:gid the daemon runs as; default 2510:2510. */
50
+ readonly user: "COMPUTER_DAYTONA_USER";
51
+ /** The snapshot every computer of the run starts from; default "default", Daytona's default snapshot. */
52
+ readonly snapshot: "COMPUTER_DAYTONA_SNAPSHOT";
53
+ };
54
+ /**
55
+ * The provider's options this module reads from env, each only when its name is set; throws in words without the key,
56
+ * never echoing one. create() checks the rest.
57
+ */
58
+ export declare function settingsFromEnv(env?: Record<string, string | undefined>): DaytonaCreateOptions;
59
+ /** Minutes without outside activity before Daytona stops a run's sandbox: at most 30, so none outlives a run for long. */
60
+ export declare const CONFORMANCE_AUTO_STOP_MINUTES = 30;
61
+ /** Minutes a run's sandbox may stay stopped: 0, Daytona deletes it as soon as it stops. */
62
+ export declare const CONFORMANCE_AUTO_DELETE_MINUTES = 0;
63
+ /**
64
+ * For the run's report: what this configuration means for the suite. The provider declares it (stopDeletes), and the
65
+ * note says it in words.
66
+ */
67
+ export declare const conformanceNotes: string[];
68
+ export interface DaytonaModuleOptions {
69
+ /** Where the settings are read; default process.env. */
70
+ env?: Record<string, string | undefined>;
71
+ fetch?: DaytonaProviderOptions["fetch"];
72
+ webSocket?: DaytonaProviderOptions["webSocket"];
73
+ /** The provider's bounds; the sweep sets how long a release waits. */
74
+ timeouts?: DaytonaProviderOptions["timeouts"];
75
+ /** What the provider says that is no failure: the CLI gives it and puts it in the report. */
76
+ onNote?: DaytonaProviderOptions["onNote"];
77
+ }
78
+ /** The image every computer of the run starts from: COMPUTER_DAYTONA_SNAPSHOT, or Daytona's default snapshot. */
79
+ export declare function conformanceImage({ env }?: Pick<DaytonaModuleOptions, "env">): string;
80
+ /** The provider the CLI runs; throws in words when a setting is missing or wrong. */
81
+ export declare function createProvider(options?: DaytonaModuleOptions): DaytonaProvider;
82
+ /** The same provider with a daemon that reports another version, built with Go for the drift case. */
83
+ export declare function createDriftedProvider(options?: DaytonaModuleOptions): Promise<DaytonaProvider>;
@@ -0,0 +1,107 @@
1
+ // Daytona for the conformance CLI: `--provider daytona [--image <snapshot>]`. The provider reads no environment: this
2
+ // module reads the run's settings from its own COMPUTER_DAYTONA_* names (never a bare DAYTONA_ variable, which may hold
3
+ // another organization's key on a host that runs other Daytona work) and passes each to create() as its option, the key
4
+ // read only when createProvider() runs. Every sandbox of a run has a bounded life besides its TTL: Daytona stops one
5
+ // after 30 minutes with no outside activity and deletes it as soon as it stops, so a stop deletes, and the provider
6
+ // declares it (stopDeletes; see conformanceNotes).
7
+ import { create, DAYTONA_DEFAULT_SNAPSHOT } from "../daytona.js";
8
+ import { archilRunFolder, archilSettings } from "./archil.js";
9
+ import { buildDriftDaemon, DRIFT_VERSION } from "./drift-daemon.js";
10
+ /** The Archil disk's settings for the mount cases, by name (COMPUTER_ARCHIL_*: all five, or none). */
11
+ export { ARCHIL_ENV } from "./archil.js";
12
+ /**
13
+ * A fresh run folder for the mount cases: an Archil one on the disk the COMPUTER_ARCHIL_* settings name (the shared
14
+ * archilRunFolder; the run's snapshot is then one of box/Dockerfile, and COMPUTER_DAYTONA_USER is 2510:2510); none when
15
+ * they name none, and none for a bind, which a remote computer cannot take.
16
+ */
17
+ export async function mountFor(kind, { env = process.env, archil = {} } = {}) {
18
+ if (kind !== "archil")
19
+ return undefined;
20
+ const settings = archilSettings(env);
21
+ return settings === undefined ? undefined : archilRunFolder({ ...settings, ...archil });
22
+ }
23
+ /** The environment this module reads, by name, each for the option its comment names. */
24
+ export const DAYTONA_ENV = {
25
+ /** apiKey, required: the Daytona API key. */
26
+ key: "COMPUTER_DAYTONA_API_KEY",
27
+ /** apiUrl; default https://app.daytona.io/api. */
28
+ url: "COMPUTER_DAYTONA_API_URL",
29
+ /** daemonPath; default this package's dist/computerd-linux-<arch>. */
30
+ daemon: "COMPUTER_DAYTONA_DAEMON",
31
+ /** arch: amd64 (default) or arm64, the sandboxes' architecture. */
32
+ arch: "COMPUTER_DAYTONA_ARCH",
33
+ /** target: the Daytona target (region); default the organization's. */
34
+ target: "COMPUTER_DAYTONA_TARGET",
35
+ /** sandboxClass: container (default) or linux-vm, the class the snapshot makes. */
36
+ sandboxClass: "COMPUTER_DAYTONA_CLASS",
37
+ /** daemonUser: uid:gid the daemon runs as; default 2510:2510. */
38
+ user: "COMPUTER_DAYTONA_USER",
39
+ /** The snapshot every computer of the run starts from; default "default", Daytona's default snapshot. */
40
+ snapshot: "COMPUTER_DAYTONA_SNAPSHOT",
41
+ };
42
+ /** The names this module reads, under the conformance modules' common name (ConformanceModule.ENV). */
43
+ export const ENV = DAYTONA_ENV;
44
+ /**
45
+ * The provider's options this module reads from env, each only when its name is set; throws in words without the key,
46
+ * never echoing one. create() checks the rest.
47
+ */
48
+ export function settingsFromEnv(env = process.env) {
49
+ const apiKey = env[DAYTONA_ENV.key];
50
+ if (apiKey === undefined || apiKey === "")
51
+ throw new Error(`set ${DAYTONA_ENV.key} to a Daytona API key: the conformance module reads it there and nowhere else, never from DAYTONA_API_KEY`);
52
+ const named = (name) => (env[name] ? { value: env[name] } : undefined);
53
+ const url = named(DAYTONA_ENV.url);
54
+ const target = named(DAYTONA_ENV.target);
55
+ const daemon = named(DAYTONA_ENV.daemon);
56
+ const arch = named(DAYTONA_ENV.arch);
57
+ const sandboxClass = named(DAYTONA_ENV.sandboxClass);
58
+ const user = named(DAYTONA_ENV.user);
59
+ return {
60
+ apiKey,
61
+ ...(url ? { apiUrl: url.value } : {}),
62
+ ...(target ? { target: target.value } : {}),
63
+ ...(daemon ? { daemonPath: daemon.value } : {}),
64
+ ...(arch ? { arch: arch.value } : {}),
65
+ // create() refuses any other class in words.
66
+ ...(sandboxClass ? { sandboxClass: sandboxClass.value } : {}),
67
+ ...(user ? { daemonUser: user.value } : {}),
68
+ };
69
+ }
70
+ /** Minutes without outside activity before Daytona stops a run's sandbox: at most 30, so none outlives a run for long. */
71
+ export const CONFORMANCE_AUTO_STOP_MINUTES = 30;
72
+ /** Minutes a run's sandbox may stay stopped: 0, Daytona deletes it as soon as it stops. */
73
+ export const CONFORMANCE_AUTO_DELETE_MINUTES = 0;
74
+ /**
75
+ * For the run's report: what this configuration means for the suite. The provider declares it (stopDeletes), and the
76
+ * note says it in words.
77
+ */
78
+ export const conformanceNotes = [
79
+ `daytona: every sandbox runs with autoStopMinutes ${CONFORMANCE_AUTO_STOP_MINUTES} and autoDeleteMinutes ${CONFORMANCE_AUTO_DELETE_MINUTES}, besides its TTL: Daytona deletes a sandbox as soon as it stops, so this configuration keeps no stopped computer, and the provider declares stopDeletes. Core provider.stop holds it to that: a stopped computer is gone, neither listed nor attachable. Full provider.janitor, which needs a stopped computer kept, is skipped (the lifetime being vendor).`,
80
+ ];
81
+ /** The provider's options: what this module reads from the environment (settingsFromEnv), with the run's bounds. */
82
+ function optionsOf({ env = process.env, fetch, webSocket, timeouts, onNote }) {
83
+ return {
84
+ ...settingsFromEnv(env),
85
+ autoStopMinutes: CONFORMANCE_AUTO_STOP_MINUTES,
86
+ autoDeleteMinutes: CONFORMANCE_AUTO_DELETE_MINUTES,
87
+ ...(fetch ? { fetch } : {}),
88
+ ...(webSocket ? { webSocket } : {}),
89
+ ...(timeouts ? { timeouts } : {}),
90
+ ...(onNote ? { onNote } : {}),
91
+ };
92
+ }
93
+ /** The image every computer of the run starts from: COMPUTER_DAYTONA_SNAPSHOT, or Daytona's default snapshot. */
94
+ export function conformanceImage({ env = process.env } = {}) {
95
+ return env[DAYTONA_ENV.snapshot] || DAYTONA_DEFAULT_SNAPSHOT;
96
+ }
97
+ /** The provider the CLI runs; throws in words when a setting is missing or wrong. */
98
+ export function createProvider(options = {}) {
99
+ return create(optionsOf(options));
100
+ }
101
+ /** The same provider with a daemon that reports another version, built with Go for the drift case. */
102
+ export async function createDriftedProvider(options = {}) {
103
+ const settings = optionsOf(options);
104
+ // Every setting is checked before Go builds anything.
105
+ create(settings);
106
+ return create({ ...settings, daemonPath: await buildDriftDaemon(settings.arch ?? "amd64", DRIFT_VERSION) });
107
+ }
@@ -0,0 +1,38 @@
1
+ import { type DockerCreateOptions, type DockerProvider } from "../docker.js";
2
+ import type { MountKind } from "../mount.js";
3
+ import type { RunFolder } from "./types.js";
4
+ /** The environment this module reads, by name. */
5
+ export declare const DOCKER_ENV: {
6
+ /** The daemon binary for Docker's architecture; default this package's dist/computerd-linux-<arch>. */
7
+ readonly daemon: "COMPUTER_DOCKER_DAEMON";
8
+ /** The directory of the provider's 0755 copy of the daemon; default ~/.cache/agentrun-computer. See DockerProviderOptions.daemonCache. */
9
+ readonly daemonCache: "COMPUTER_DOCKER_DAEMON_CACHE";
10
+ /** Who a computer runs as when its spec does not say, uid or uid:gid in numbers; see DockerProviderOptions.user. */
11
+ readonly user: "COMPUTER_DOCKER_USER";
12
+ };
13
+ /** The names this module reads, under the conformance modules' common name (ConformanceModule.ENV). */
14
+ export declare const ENV: {
15
+ /** The daemon binary for Docker's architecture; default this package's dist/computerd-linux-<arch>. */
16
+ readonly daemon: "COMPUTER_DOCKER_DAEMON";
17
+ /** The directory of the provider's 0755 copy of the daemon; default ~/.cache/agentrun-computer. See DockerProviderOptions.daemonCache. */
18
+ readonly daemonCache: "COMPUTER_DOCKER_DAEMON_CACHE";
19
+ /** Who a computer runs as when its spec does not say, uid or uid:gid in numbers; see DockerProviderOptions.user. */
20
+ readonly user: "COMPUTER_DOCKER_USER";
21
+ };
22
+ /** The provider's options this module reads from env, each only when its name is set. */
23
+ export declare function settingsFromEnv(env?: Record<string, string | undefined>): DockerCreateOptions;
24
+ export interface DockerModuleOptions extends Pick<DockerCreateOptions, "docker" | "timeoutMs" | "desktop"> {
25
+ /** Where the settings are read; default process.env. */
26
+ env?: Record<string, string | undefined>;
27
+ }
28
+ /** The provider the CLI runs; throws in words when Docker cannot be asked its architecture, or its daemon is not built. */
29
+ export declare function createProvider({ env, ...options }?: DockerModuleOptions): Promise<DockerProvider>;
30
+ /** The same provider with a daemon that reports another version, for the drift.version case. */
31
+ export declare function createDriftedProvider({ env, ...options }?: DockerModuleOptions): Promise<DockerProvider>;
32
+ /**
33
+ * A run folder for a bind, and none for any other kind: a new directory under the temp dir, by its canonical path, owned
34
+ * by the computer's user (the provider's, as createProvider builds it) as the provider requires. This process owns it
35
+ * already when it is that user; as root, it gives the folder to that user, as a caller does: the provider never changes
36
+ * the folder. The runner closes it when its case ends.
37
+ */
38
+ export declare function mountFor(kind: MountKind, { env, ...options }?: DockerModuleOptions): Promise<RunFolder | undefined>;
@@ -0,0 +1,70 @@
1
+ // Docker for the conformance CLI (`--provider docker`): the provider as create() builds it from the settings this module
2
+ // reads (COMPUTER_DOCKER_DAEMON, COMPUTER_DOCKER_DAEMON_CACHE, COMPUTER_DOCKER_USER), and its drifted twin, the same
3
+ // provider with a daemon of another version, built with Go for Docker's architecture when the drift case first asks. The
4
+ // provider reads no environment: this module reads these names and passes them in as options. With desktop, both are
5
+ // desktops (kind desktop) on an image with an X server, such as test/fixtures/desktop/Dockerfile's. For the mount cases,
6
+ // mountFor("bind") makes a run folder on this host, owned by the computer's user.
7
+ import { chownSync, mkdtempSync, realpathSync } from "node:fs";
8
+ import { readFile, rm, writeFile } from "node:fs/promises";
9
+ import { tmpdir } from "node:os";
10
+ import { join } from "node:path";
11
+ import { create, dockerArch } from "../docker.js";
12
+ import { buildDriftDaemon } from "./drift-daemon.js";
13
+ /** The environment this module reads, by name. */
14
+ export const DOCKER_ENV = {
15
+ /** The daemon binary for Docker's architecture; default this package's dist/computerd-linux-<arch>. */
16
+ daemon: "COMPUTER_DOCKER_DAEMON",
17
+ /** The directory of the provider's 0755 copy of the daemon; default ~/.cache/agentrun-computer. See DockerProviderOptions.daemonCache. */
18
+ daemonCache: "COMPUTER_DOCKER_DAEMON_CACHE",
19
+ /** Who a computer runs as when its spec does not say, uid or uid:gid in numbers; see DockerProviderOptions.user. */
20
+ user: "COMPUTER_DOCKER_USER",
21
+ };
22
+ /** The names this module reads, under the conformance modules' common name (ConformanceModule.ENV). */
23
+ export const ENV = DOCKER_ENV;
24
+ /** The provider's options this module reads from env, each only when its name is set. */
25
+ export function settingsFromEnv(env = process.env) {
26
+ return {
27
+ ...(env[DOCKER_ENV.daemon] ? { daemonPath: env[DOCKER_ENV.daemon] } : {}),
28
+ ...(env[DOCKER_ENV.daemonCache] ? { daemonCache: env[DOCKER_ENV.daemonCache] } : {}),
29
+ ...(env[DOCKER_ENV.user] ? { user: env[DOCKER_ENV.user] } : {}),
30
+ };
31
+ }
32
+ /** The provider the CLI runs; throws in words when Docker cannot be asked its architecture, or its daemon is not built. */
33
+ export function createProvider({ env = process.env, ...options } = {}) {
34
+ return create({ ...settingsFromEnv(env), ...options });
35
+ }
36
+ /** The same provider with a daemon that reports another version, for the drift.version case. */
37
+ export async function createDriftedProvider({ env = process.env, ...options } = {}) {
38
+ const daemonPath = await buildDriftDaemon(await dockerArch(options));
39
+ return create({ ...settingsFromEnv(env), ...options, daemonPath });
40
+ }
41
+ /**
42
+ * A run folder for a bind, and none for any other kind: a new directory under the temp dir, by its canonical path, owned
43
+ * by the computer's user (the provider's, as createProvider builds it) as the provider requires. This process owns it
44
+ * already when it is that user; as root, it gives the folder to that user, as a caller does: the provider never changes
45
+ * the folder. The runner closes it when its case ends.
46
+ */
47
+ export async function mountFor(kind, { env = process.env, ...options } = {}) {
48
+ if (kind !== "bind")
49
+ return undefined;
50
+ const { user } = await createProvider({ env, ...options });
51
+ const dir = realpathSync(mkdtempSync(join(tmpdir(), "computer-run-")));
52
+ const [uid = -1, gid = -1] = user.split(":").map(Number);
53
+ if (process.getuid?.() === 0)
54
+ chownSync(dir, uid, gid);
55
+ return {
56
+ mount: { kind: "bind", path: dir },
57
+ read: async (path) => {
58
+ try {
59
+ return await readFile(join(dir, path));
60
+ }
61
+ catch (error) {
62
+ if (error.code === "ENOENT")
63
+ return undefined;
64
+ throw error;
65
+ }
66
+ },
67
+ write: (path, data) => writeFile(join(dir, path), data, { mode: 0o644 }),
68
+ close: () => rm(dir, { recursive: true, force: true }),
69
+ };
70
+ }
@@ -0,0 +1,8 @@
1
+ /** The version a drifted daemon reports: this package's, which every provider reports, with -drift. */
2
+ export declare const DRIFT_VERSION: string;
3
+ /**
4
+ * This package's daemon for linux/<arch>, stamped with version, built with Go into a directory of its own that is
5
+ * removed when the process exits; its path. The directory is 0755, so a computer's user, with no capabilities, can
6
+ * reach and run a binary mounted from it.
7
+ */
8
+ export declare function buildDriftDaemon(arch: string, version?: string): Promise<string>;
@@ -0,0 +1,41 @@
1
+ // The daemon of another version every conformance module's drifted twin runs, built with Go for the drift case.
2
+ import { execFile } from "node:child_process";
3
+ import { chmodSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+ const VERSION = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8")).version;
8
+ /** The version a drifted daemon reports: this package's, which every provider reports, with -drift. */
9
+ export const DRIFT_VERSION = `${VERSION}-drift`;
10
+ /** Go's own settings and the target, and nothing else of this process's environment: never a key. */
11
+ function goEnv(arch) {
12
+ const kept = ["PATH", "HOME", "TMPDIR", "GOPATH", "GOCACHE", "GOMODCACHE", "GOFLAGS", "GOPROXY", "GOTOOLCHAIN"];
13
+ const env = { CGO_ENABLED: "0", GOOS: "linux", GOARCH: arch };
14
+ for (const name of kept) {
15
+ const value = process.env[name];
16
+ if (value !== undefined)
17
+ env[name] = value;
18
+ }
19
+ return env;
20
+ }
21
+ /**
22
+ * This package's daemon for linux/<arch>, stamped with version, built with Go into a directory of its own that is
23
+ * removed when the process exits; its path. The directory is 0755, so a computer's user, with no capabilities, can
24
+ * reach and run a binary mounted from it.
25
+ */
26
+ export async function buildDriftDaemon(arch, version = DRIFT_VERSION) {
27
+ const dir = mkdtempSync(join(tmpdir(), "computer-drift-"));
28
+ process.once("exit", () => rmSync(dir, { recursive: true, force: true }));
29
+ chmodSync(dir, 0o755);
30
+ const out = join(dir, "computerd");
31
+ await new Promise((resolve, reject) => {
32
+ execFile("go", ["build", "-trimpath", "-ldflags", `-s -w -X main.version=${version}`, "-o", out, "./cmd/computerd"], { cwd: fileURLToPath(new URL("../../daemon", import.meta.url)), env: goEnv(arch) }, (error, _stdout, stderr) => {
33
+ if (!error)
34
+ return resolve();
35
+ const why = error.code === "ENOENT" ? "go was not found on PATH" : stderr.trim() || error.message;
36
+ reject(new Error(`building a daemon of another version for the drift case: ${why}`));
37
+ });
38
+ });
39
+ chmodSync(out, 0o755);
40
+ return out;
41
+ }
@@ -0,0 +1,16 @@
1
+ import { type E2BOptions } from "../e2b.js";
2
+ /** A stream as main writes to it: done is called once the text is handed on. */
3
+ export interface Writer {
4
+ write(text: string, done?: (error?: Error | null) => void): unknown;
5
+ }
6
+ export interface DiagnoseIo extends Pick<E2BOptions, "Sandbox" | "daemonPath" | "timeouts"> {
7
+ /** Where the settings are read; default process.env. */
8
+ env?: Record<string, string | undefined>;
9
+ stdout?: Writer;
10
+ stderr?: Writer;
11
+ /** Aborts the diagnostic: the sandbox is still killed and read back gone. */
12
+ signal?: AbortSignal;
13
+ /** The longest the diagnostic runs before it aborts itself; default 8 minutes, inside the sandbox's 10. */
14
+ boundMs?: number;
15
+ }
16
+ export declare function main(argv: string[], io?: DiagnoseIo): Promise<number>;
@@ -0,0 +1,61 @@
1
+ // The E2B network diagnostic, run once by hand with a key the lead has OKed:
2
+ //
3
+ // AGENTRUN_COMPUTER_LIVE_E2B=1 COMPUTER_E2B_API_KEY=... node packages/computer/dist/conformance/e2b-diagnose.js
4
+ //
5
+ // E2B documents that its firewall accepts an outbound TCP connection before it decides whether the destination is
6
+ // allowed, so from inside a sandbox with no internet access a connection can succeed while nothing reaches the
7
+ // destination (docs.e2b.dev network/internet-access, "Behavior of blocked TCP connections"). The provider's network-none
8
+ // probe refuses only on an answer and records an accept with nothing back in its notes. This makes ONE sandbox exactly as the provider makes one for network
9
+ // none (diagnoseNetworkNone in ../e2b.ts: the same create options, read-back, upload and sha256 check), runs
10
+ // `computerd probe --diagnose` in it (per well-known public address and port: refused, accepted with no answer, or
11
+ // answered), prints one JSON line, then kills the sandbox and reads it back gone, on an error and on an abort (SIGINT,
12
+ // SIGTERM, or the run's own 8-minute bound) too. Its E2B timeout is 10 minutes. It changes nothing in the provider.
13
+ //
14
+ // Settings are the conformance module's (COMPUTER_E2B_API_KEY, COMPUTER_E2B_DOMAIN, COMPUTER_E2B_KIND,
15
+ // COMPUTER_E2B_DAEMON and the rest settingsFromEnv reads; never E2B_API_KEY), passed to the provider's create(), and the
16
+ // template is COMPUTER_E2B_TEMPLATE as for conformance (default "desktop"). The live switch is checked before any of
17
+ // them is read. Exit 0 when a diagnosis came back and the sandbox reads gone, 1 otherwise, 2 on a usage error, no live
18
+ // switch, or a setting the provider refuses (nothing is made then).
19
+ import { create, diagnoseNetworkNone } from "../e2b.js";
20
+ import { isCommand } from "../entry.js";
21
+ import { conformanceImage, E2B_ENV, settingsFromEnv } from "./e2b.js";
22
+ const USAGE = `usage: ${E2B_ENV.live}=1 ${E2B_ENV.key}=<key> node packages/computer/dist/conformance/e2b-diagnose.js
23
+ makes one E2B sandbox as the provider makes one for network none, runs computerd probe --diagnose in it, prints one
24
+ JSON line, and kills the sandbox and reads it back gone. It takes no argument; the template is ${E2B_ENV.template}.
25
+ exit: 0 diagnosed and gone, 1 otherwise, 2 usage error, no live switch, or a refused setting`;
26
+ const BOUND_MS = 8 * 60_000;
27
+ const write = (stream, text) => new Promise((resolve) => void stream.write(text, () => resolve()));
28
+ export async function main(argv, io = {}) {
29
+ const { env = process.env, stdout = process.stdout, stderr = process.stderr, boundMs = BOUND_MS } = io;
30
+ if (env[E2B_ENV.live] !== "1") {
31
+ await write(stderr, `the E2B network diagnostic makes a real sandbox: set ${E2B_ENV.live}=1, with a key the lead has OKed, to run it\n`);
32
+ return 2;
33
+ }
34
+ if (argv.length > 0) {
35
+ await write(stderr, `it takes no argument, not ${argv.join(" ")}\n${USAGE}\n`);
36
+ return 2;
37
+ }
38
+ const key = env[E2B_ENV.key] ?? "";
39
+ // Nothing the SDK or E2B says reaches an output with the key in it.
40
+ const clean = (text) => (key === "" ? text : text.split(key).join("[key]"));
41
+ let provider;
42
+ try {
43
+ provider = await create({ ...settingsFromEnv(env), ...(io.Sandbox ? { Sandbox: io.Sandbox } : {}), ...(io.daemonPath === undefined ? {} : { daemonPath: io.daemonPath }), ...(io.timeouts ? { timeouts: io.timeouts } : {}) });
44
+ }
45
+ catch (error) {
46
+ await write(stderr, `${clean(error.message)}\n`);
47
+ return 2;
48
+ }
49
+ const signal = AbortSignal.any([AbortSignal.timeout(boundMs), ...(io.signal ? [io.signal] : [])]);
50
+ const report = await diagnoseNetworkNone(provider, { image: conformanceImage({ env }), signal });
51
+ await write(stdout, `${clean(JSON.stringify(report))}\n`);
52
+ if (!report.released.gone)
53
+ await write(stderr, `the sandbox was not read back gone: ${clean(report.released.words)}\n`);
54
+ return report.diagnosis !== undefined && report.released.gone ? 0 : 1;
55
+ }
56
+ if (isCommand(import.meta)) {
57
+ const controller = new AbortController();
58
+ for (const name of ["SIGINT", "SIGTERM"])
59
+ process.once(name, () => controller.abort());
60
+ process.exitCode = await main(process.argv.slice(2), { signal: controller.signal });
61
+ }
@@ -0,0 +1,18 @@
1
+ import { type E2BSandboxClass } from "../e2b.js";
2
+ /** A stream as main writes to it: done is called once the text is handed on. */
3
+ export interface Writer {
4
+ write(text: string, done?: (error?: Error | null) => void): unknown;
5
+ }
6
+ export interface SweepIo {
7
+ /** Where the settings are read; default process.env. */
8
+ env?: Record<string, string | undefined>;
9
+ /** The SDK's Sandbox class; imported from the host's e2b package by default. */
10
+ Sandbox?: E2BSandboxClass;
11
+ stdout?: Writer;
12
+ stderr?: Writer;
13
+ /** How long --after reads one killed sandbox back before it counts as still there; default 60 s. */
14
+ waitMs?: number;
15
+ /** The pause between two reads of one sandbox; default 2 s. */
16
+ pollMs?: number;
17
+ }
18
+ export declare function main(argv: string[], io?: SweepIo): Promise<number>;