@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
package/dist/daytona.d.ts CHANGED
@@ -18,7 +18,7 @@ export type DaytonaTimeouts = HostedTimeouts & {
18
18
  retryMs: number;
19
19
  };
20
20
  /** The Daytona provider's options: the key and Daytona's own settings, then the shared adapter's (HostedOptions). */
21
- export interface DaytonaProviderOptions extends Omit<HostedOptions, "kind" | "desktop" | "maxLifetimeMs" | "timeouts" | "archilEgress"> {
21
+ export interface DaytonaProviderOptions extends Omit<HostedOptions, "kind" | "desktop" | "maxLifetimeMs" | "timeouts"> {
22
22
  /** The Daytona API key. The caller passes it; this provider never reads the environment and never puts it in a computer. */
23
23
  apiKey: string;
24
24
  /** Default https://app.daytona.io/api. */
@@ -29,6 +29,13 @@ export interface DaytonaProviderOptions extends Omit<HostedOptions, "kind" | "de
29
29
  sandboxClass?: "container" | "linux-vm";
30
30
  /** The Daytona target (region); default the organization's. */
31
31
  target?: string;
32
+ /**
33
+ * The operator's Archil egress relay, `<IPv4 gateway>:<mount lane>:<data lane>` (HostedOptions.archilEgress, checked
34
+ * as the adapter checks it): for a self-hosted Daytona target whose sandboxes reach Archil only through it. With it,
35
+ * this provider takes an Archil mount (DAYTONA.mountsWith); without it, check() refuses one in DAYTONA_NO_ARCHIL's
36
+ * words, since Archil's client hangs on Daytona's hosted cloud. Set it only for such a target.
37
+ */
38
+ archilEgress?: string;
32
39
  /**
33
40
  * The snapshot GPU computers are made from: one of ours, box/Dockerfile built with a GPU (box/build-daytona.py --gpu
34
41
  * H100 prints its name, agentrun-archil-gpu-h100-<hash>), whose user is root; its GPU is the one its name says.
package/dist/daytona.js CHANGED
@@ -1,13 +1,14 @@
1
1
  // The Daytona host: Daytona sandboxes over Daytona's v0 REST API with fetch (no SDK). Daytona's toolbox daemon is the
2
2
  // sandbox's first process, so computerd is a child: its upload goes through the toolbox's file API, and every command
3
- // (install, init's start, the stdio bridge) is a session command, its output read from the command's log stream and its
4
- // stdin sent as the command's input. The rest of the computer is the shared machine-host adapter's (./hosted/provider.ts).
5
- // Every Daytona fact used here is cited in the README's Daytona section.
3
+ // (install, init's start, the stdio bridge, an Archil computer's root steps) is a session command, its output read from
4
+ // the command's log stream and its stdin sent as the command's input. The rest of the computer is the shared
5
+ // machine-host adapter's (./hosted/provider.ts). Every Daytona fact used here is cited in the README's Daytona section.
6
6
  import { randomBytes } from "node:crypto";
7
- import { PassThrough } from "node:stream";
8
- import { DAYTONA, DAYTONA_DEFAULT_SNAPSHOT, DAYTONA_GPU, DAYTONA_GPU_REGION, DAYTONA_NO_ARCHIL, daytonaGpuSnapshot } from "./descriptors/daytona.js";
7
+ import { mountsOf } from "./descriptor.js";
8
+ import { DAYTONA, DAYTONA_DEFAULT_SNAPSHOT, DAYTONA_GPU, DAYTONA_GPU_REGION, daytonaGpuSnapshot } from "./descriptors/daytona.js";
9
9
  import { COMPUTER_LABEL } from "./drift.js";
10
10
  import { HostError } from "./host.js";
11
+ import { framedExec } from "./hosted/framed-exec.js";
11
12
  import { HostedProvider, timeoutsOf } from "./hosted/provider.js";
12
13
  import { boundOf, orThrow, pause as sleep } from "./hosted/process.js";
13
14
  import { allPages, jsonOf, rest } from "./hosted/rest.js";
@@ -84,12 +85,12 @@ async function sandboxOf(api, idOrName, signal) {
84
85
  const sb = found.value;
85
86
  return typeof sb?.id === "string" ? ok(sb) : vendorFail("daytona", `GET /sandbox/${idOrName}: no sandbox in the answer`);
86
87
  }
87
- /** The log stream's output for one channel: a failure ends the stream with it, and one nobody reads is not an uncaught error. */
88
- const channel = () => new PassThrough().on("error", () => { });
89
- const push = (stream, bytes) => void (stream.writableEnded || stream.destroyed || stream.write(bytes));
90
- const finish = (stream, error) => void (error ? stream.destroy(error) : stream.end());
91
88
  /** Daytona's sandboxes as a MachineHost (../host.ts). */
92
89
  class DaytonaHost {
90
+ /**
91
+ * Daytona's descriptor, the registry's, as the constructor gives it with the mounts of the keys this provider was made
92
+ * with (mountsOf): an Archil mount with an Archil egress, none without.
93
+ */
93
94
  descriptor = DAYTONA;
94
95
  facts;
95
96
  /** Daytona's REST API: the control plane, and the toolbox of each sandbox. */
@@ -105,6 +106,7 @@ class DaytonaHost {
105
106
  /** Each sandbox's toolbox URL, by id, once read: let go of at its delete. */
106
107
  #toolboxes = new Map();
107
108
  constructor(options) {
109
+ this.descriptor = options.descriptor;
108
110
  this.#rest = options.rest;
109
111
  this.#headers = options.headers;
110
112
  this.#webSocket = options.webSocket;
@@ -164,8 +166,8 @@ class DaytonaHost {
164
166
  }
165
167
  /**
166
168
  * POST /sandbox: its native name and labels, the lifetime as a TTL in whole minutes, the idle stop and auto-delete,
167
- * no public port, and network none (block-all), the one network check() takes. A GPU
168
- * computer is made from the GPU snapshot in region earth, ephemeral (its stop deletes it). Never cancelled: the adapter
169
+ * no public port, and network none (block-all) unless the adapter asks egress (a network open or a list, or an Archil
170
+ * computer's root, which reaches Archil through the operator's relay). A GPU computer is made from the GPU snapshot in region earth, ephemeral (its stop deletes it). Never cancelled: the adapter
169
171
  * races it, and deletes by name one whose answer never comes. A name Daytona already holds (409) made nothing: exists,
170
172
  * and the adapter adopts the sandbox the name lists, as a retry does. req.backstopAt is left: the TTL is Daytona's own
171
173
  * timer at the deadline (lifetime "vendor"), and autoDeleteInterval counts from a stop, not from create.
@@ -301,37 +303,71 @@ class DaytonaHost {
301
303
  throw new HostError(older.error.code, `${missing}, then ${older.error.message}`);
302
304
  }
303
305
  /**
304
- * A session command of its own: argv as one shell line, run async with no input echo, as the toolbox's user (root, or
305
- * one with passwordless sudo, which the adapter's scripts use). Its output comes from the command's log stream, where
306
- * Daytona prefixes each stdout line with 01 01 01 and each stderr line with 02 02 02; an echo of a request the client
307
- * wrote is dropped. Writes go to the command's input, whole lines, one call after another. Its exit code is read from
308
- * the session; once it has one, the log stream is read to its end (it closes as the command ends) and the session
309
- * removed. kill closes the stream and removes the session, which ends the command.
306
+ * A session command of its own (#commands), on framedExec: argv as one shell line, run async with no input echo, as
307
+ * the toolbox's user (root, or one with passwordless sudo, which the adapter's scripts use).
310
308
  */
311
309
  async exec(id, argv, ctx) {
312
- const toolbox = await this.#toolbox(id, ctx.signal);
310
+ return framedExec(this.#commands(await this.#toolbox(id, ctx.signal)), argv, ctx);
311
+ }
312
+ /**
313
+ * Daytona's session commands in the toolbox as exec's pieces (./hosted/framed-exec.ts). start makes a session, runs
314
+ * the command in it and opens its log stream, where Daytona prefixes each stdout line with 01 01 01 and each stderr
315
+ * line with 02 02 02; an echo of a request the client wrote is dropped. The stream ends once the command's exit code
316
+ * is written (the toolbox reads the log until its exit code file holds one, daytonaio/daytona@b5a5d9e7
317
+ * apps/daemon/internal/util/log_reader.go), so the events read the exit code from the session then, never while it
318
+ * runs, within a grace for a read that lags; then the session is removed. write sends whole lines, since Daytona's
319
+ * input call ends what it is given with a newline (apps/daemon/pkg/session/input.go): the rest of a line waits for its
320
+ * end, or end(). kill closes the stream and removes the session, which ends the command.
321
+ */
322
+ #commands(toolbox) {
323
+ return {
324
+ start: (argv, ctx) => this.#startCommand(toolbox, argv, ctx),
325
+ events: (command) => this.#events(command),
326
+ write: async (command, text) => {
327
+ command.held += text;
328
+ const at = command.held.lastIndexOf("\n");
329
+ if (at < 0)
330
+ return;
331
+ const data = command.held.slice(0, at + 1);
332
+ command.held = command.held.slice(at + 1);
333
+ await this.#input(command, data);
334
+ },
335
+ end: async (command) => {
336
+ const data = command.held;
337
+ command.held = "";
338
+ if (data !== "")
339
+ await this.#input(command, data);
340
+ },
341
+ kill: async (command) => {
342
+ command.killed = true;
343
+ await this.#letGo(command);
344
+ },
345
+ };
346
+ }
347
+ async #startCommand(toolbox, argv, ctx) {
313
348
  const sessionId = `agentrun-${randomBytes(8).toString("hex")}`;
314
349
  const session = `${toolbox}/process/session/${sessionId}`;
315
350
  orThrow(await this.#rest.call("POST", `${toolbox}/process/session`, { json: { sessionId }, timeoutMs: ctx.timeoutMs }, ctx.signal));
316
- let removed;
317
- const removeSession = () => (removed ??= this.#rest.call("DELETE", session, {}).then(() => { }));
318
351
  const ran = await this.#rest.json("POST", `${session}/exec`, { json: { command: shellLine(argv), runAsync: true, suppressInputEcho: true }, timeoutMs: ctx.timeoutMs }, ctx.signal);
319
352
  const commandId = ran.ok ? ran.value?.cmdId : undefined;
320
353
  if (!ran.ok || typeof commandId !== "string") {
321
- await removeSession();
354
+ await this.#rest.call("DELETE", session, {});
322
355
  throw ran.ok ? new Error("POST exec: no command id in the answer") : new HostError(ran.error.code, ran.error.message);
323
356
  }
324
- const command = `${session}/command/${encodeURIComponent(commandId)}`;
325
357
  let socket;
326
358
  try {
327
- socket = this.#webSocket(`${command.replace(/^https:/, "wss:")}/logs?follow=true`, { headers: this.#headers, protocols: [] });
359
+ socket = this.#webSocket(`${session.replace(/^https:/, "wss:")}/command/${encodeURIComponent(commandId)}/logs?follow=true`, { headers: this.#headers, protocols: [] });
328
360
  }
329
361
  catch (error) {
330
- await removeSession();
362
+ await this.#rest.call("DELETE", session, {});
331
363
  throw new Error(`opening the log stream: ${error.message}`);
332
364
  }
333
- const out = channel();
334
- const err = channel();
365
+ const command = { session, commandId, socket, output: [], ended: false, wake: () => { }, held: "", killed: false };
366
+ const ended = (failure) => {
367
+ command.failure ??= failure;
368
+ command.ended = true;
369
+ command.wake();
370
+ };
335
371
  let rest = Buffer.alloc(0);
336
372
  const lines = (bytes, last) => {
337
373
  rest = rest.length === 0 ? bytes : Buffer.concat([rest, bytes]);
@@ -341,22 +377,19 @@ class DaytonaHost {
341
377
  const line = rest.subarray(0, end);
342
378
  rest = rest.subarray(end);
343
379
  if (line.subarray(0, 3).equals(ERR))
344
- push(err, line.subarray(3));
380
+ command.output.push({ stream: "stderr", text: line.subarray(3).toString("utf8") });
345
381
  else {
346
- const text = line.subarray(0, 3).equals(OUT) ? line.subarray(3) : line;
347
- if (!ECHO.test(text.subarray(0, 64).toString("utf8")))
348
- push(out, text);
382
+ const text = (line.subarray(0, 3).equals(OUT) ? line.subarray(3) : line).toString("utf8");
383
+ if (!ECHO.test(text.slice(0, 64)))
384
+ command.output.push({ stream: "stdout", text });
349
385
  }
350
386
  }
387
+ command.wake();
351
388
  if (rest.length > MAX_LINE_BYTES + 8) {
352
- const over = new Error("the process sent a line over the 1 MiB limit");
353
- finish(out, over);
354
- finish(err, over);
389
+ ended(new Error("the process sent a line over the 1 MiB limit"));
355
390
  socket.close(1000);
356
391
  }
357
392
  };
358
- let closed;
359
- const streamEnded = new Promise((done) => (closed = done));
360
393
  let opened;
361
394
  const open = new Promise((done) => (opened = done));
362
395
  socket.binaryType = "arraybuffer";
@@ -371,94 +404,79 @@ class DaytonaHost {
371
404
  });
372
405
  socket.addEventListener("error", (event) => {
373
406
  opened(`the log stream failed: ${event.message ?? "no reason given"}`);
374
- const failed = new Error(`the log stream failed${event.message ? `: ${event.message}` : ""}`);
375
- finish(out, failed);
376
- finish(err, failed);
377
- closed();
407
+ ended(new Error(`the log stream failed${event.message ? `: ${event.message}` : ""}`));
378
408
  });
379
409
  socket.addEventListener("close", ({ code }) => {
380
410
  opened(`the log stream closed before it opened (code ${code ?? "none"})`);
381
411
  lines(Buffer.alloc(0), true);
382
- finish(out);
383
- finish(err);
384
- closed();
412
+ ended();
385
413
  });
386
414
  // The stream opens within the call's bound, or the command is let go of: its output would be lost.
387
415
  const bound = boundOf(ctx.timeoutMs, ctx.signal, "opening the log stream");
388
- const kill = async () => {
389
- socket.close(1000);
390
- finish(out);
391
- finish(err);
392
- await removeSession();
393
- };
394
416
  try {
395
417
  const failed = await Promise.race([open, bound.promise]);
396
418
  if (failed !== undefined)
397
419
  throw new Error(failed);
398
420
  }
399
421
  catch (error) {
400
- await kill();
422
+ await this.#letGo(command);
401
423
  throw error;
402
424
  }
403
425
  finally {
404
426
  bound.clear();
405
427
  }
406
- // Input: whole lines, one call after another; the rest of a line waits for its end (or end()).
407
- // ignoreBOM: a U+FEFF that starts stdin is text, never a mark to drop.
408
- const utf8 = new TextDecoder("utf-8", { ignoreBOM: true });
409
- let queued = "";
410
- let sending = Promise.resolve();
411
- const send = (data) => {
412
- sending = sending.then(async () => {
413
- // Daytona's own 500 alone is sent again: the line reached no reader (internalRefusal), so it is never read
414
- // twice; a line read twice would be a JSON-RPC request run twice.
415
- const sent = await this.#rest.call("POST", `${command}/input`, { json: { data }, retry: internalRefusal });
416
- // Its words never hold what was written: it may be a disk's token.
417
- if (!sent.ok)
418
- throw new Error(`writing to the command failed (${sent.error.code}): ${sent.error.message}`);
419
- });
420
- return sending;
421
- };
422
- let exited;
423
- const exitCode = async () => {
428
+ return command;
429
+ }
430
+ /** The command's output as its log stream gives it, then its exit code; the session is removed once they end. */
431
+ async *#events(command) {
432
+ try {
424
433
  for (;;) {
425
- const read = await this.#rest.json("GET", session, { retry: true });
426
- if (!read.ok) {
427
- // The command may run on, its stream open: let go of both, and fail with the read's own words.
428
- await kill();
434
+ const next = command.output.shift();
435
+ if (next !== undefined)
436
+ yield next;
437
+ else if (command.ended)
438
+ break;
439
+ else
440
+ await new Promise((done) => (command.wake = done));
441
+ }
442
+ if (command.failure)
443
+ throw command.failure;
444
+ if (command.killed)
445
+ return;
446
+ const until = Date.now() + LOG_GRACE_MS;
447
+ for (;;) {
448
+ const read = await this.#rest.json("GET", command.session, { retry: true });
449
+ if (!read.ok)
429
450
  throw new Error(`reading the command's exit code failed (${read.error.code}): ${read.error.message}`);
430
- }
431
- const found = (read.value?.commands ?? []).find((one) => one.id === commandId);
451
+ const found = (read.value?.commands ?? []).find((one) => one.id === command.commandId);
432
452
  if (typeof found?.exitCode === "number") {
433
- // The stream closes as the command ends; one that trails is let go of after a grace.
434
- await Promise.race([streamEnded, sleep(LOG_GRACE_MS)]);
435
- await kill();
436
- return found.exitCode;
453
+ yield { exit: found.exitCode };
454
+ return;
437
455
  }
456
+ // A stream that closed with the command still running (none written within the grace) is an exit never read.
457
+ if (Date.now() >= until)
458
+ return;
438
459
  await sleep(this.#pollMs);
439
460
  }
440
- };
441
- return {
442
- stdout: out,
443
- stderr: err,
444
- write: (bytes) => {
445
- queued += utf8.decode(bytes, { stream: true });
446
- const at = queued.lastIndexOf("\n");
447
- if (at < 0)
448
- return sending;
449
- const data = queued.slice(0, at + 1);
450
- queued = queued.slice(at + 1);
451
- return send(data);
452
- },
453
- end: () => {
454
- queued += utf8.decode();
455
- const data = queued;
456
- queued = "";
457
- return data === "" ? sending : send(data);
458
- },
459
- wait: () => (exited ??= exitCode()),
460
- kill,
461
- };
461
+ }
462
+ finally {
463
+ await this.#letGo(command);
464
+ }
465
+ }
466
+ /**
467
+ * Text to the command's input, one call. Daytona's own 500 alone is sent again: the line reached no reader
468
+ * (internalRefusal), so it is never read twice; a line read twice would be a JSON-RPC request run twice.
469
+ */
470
+ async #input(command, data) {
471
+ const sent = await this.#rest.call("POST", `${command.session}/command/${encodeURIComponent(command.commandId)}/input`, { json: { data }, retry: internalRefusal });
472
+ // Its words never hold what was written: it may be a disk's token.
473
+ if (!sent.ok)
474
+ throw new Error(`writing to the command failed (${sent.error.code}): ${sent.error.message}`);
475
+ }
476
+ /** Closes the command's log stream and removes its session, once. */
477
+ #letGo(command) {
478
+ command.socket.close(1000);
479
+ return (command.removed ??= this.#rest.call("DELETE", command.session, {}).then(() => { }));
462
480
  }
463
481
  }
464
482
  /**
@@ -471,8 +489,6 @@ export class DaytonaProvider extends HostedProvider {
471
489
  const { apiKey, apiUrl = DEFAULT_API_URL, arch = "amd64", sandboxClass = "container", target, gpuSnapshot, autoStopMinutes = 0, autoDeleteMinutes, fetch: fetcher, webSocket, pause, timeouts = {}, ...hosted } = options ?? {};
472
490
  if (typeof apiKey !== "string" || apiKey === "")
473
491
  throw new Error("options.apiKey, the Daytona API key, is required: the provider reads no environment, so the caller passes it");
474
- if (hosted.archilEgress !== undefined)
475
- throw new Error(`${DAYTONA_NO_ARCHIL}, so it takes no archilEgress`);
476
492
  const base = new URL(apiUrl);
477
493
  if (base.protocol !== "https:")
478
494
  throw new Error(`the Daytona API URL must be https, so the key never crosses in the clear: ${base.protocol}`);
@@ -492,7 +508,14 @@ export class DaytonaProvider extends HostedProvider {
492
508
  throw new Error(`timeouts.retryMs must be a whole number of ms above 0, not ${retryMs}`);
493
509
  const { requestMs, pollMs } = timeoutsOf(hostedTimeouts);
494
510
  const headers = headersOf(apiKey);
511
+ // The keys it was made with, by the options they fill: DAYTONA_ARCHIL_EGRESS's archilEgress turns its Archil mount on.
512
+ const given = options;
513
+ const set = (name) => {
514
+ const value = given[DAYTONA.keys.find((key) => key.name === name)?.option ?? ""];
515
+ return typeof value === "string" && value !== "";
516
+ };
495
517
  const host = new DaytonaHost({
518
+ descriptor: { ...DAYTONA, ...mountsOf(DAYTONA, set) },
496
519
  rest: rest({ base: apiUrl, headers: () => headers, vendor: "daytona", fetch: fetcher ?? fetch, timeoutMs: requestMs, retry: { attempts: RETRY_ATTEMPTS, baseMs: retryMs, ...(pause ? { pause } : {}) }, explain }),
497
520
  headers,
498
521
  webSocket: webSocket ?? ((url, init) => new WebSocket(url, init)),
@@ -65,6 +65,14 @@ export interface ProviderDescriptor<Module extends ProviderModule = ProviderModu
65
65
  * refuses such a mount in these words, and serve says them where the run's folder can't be had (Daytona's archil).
66
66
  */
67
67
  readonly unmounted?: Unmounted;
68
+ /**
69
+ * Mount kinds its computers take only where the operator sets one of its keys, each by that key's name: the provider
70
+ * that key fills declares the kind, and one made without it refuses the kind in its unmounted words (Daytona's archil,
71
+ * with DAYTONA_ARCHIL_EGRESS: a self-hosted Daytona target reaches Archil through an egress relay, and Archil's client
72
+ * hangs on Daytona's hosted cloud). Each kind is in unmounted and never in mounts; each key is one of keys, not
73
+ * required. mountsOf gives a provider's mounts with the keys set.
74
+ */
75
+ readonly mountsWith?: Readonly<Partial<Record<MountKind, string>>>;
68
76
  /**
69
77
  * The network forms its computers make and enforce, as its providers' capabilities().network declare them: ["none"],
70
78
  * a remote computer whose programs run in a network of their own and nothing else; ["open"], the vendor's own network,
@@ -84,7 +92,11 @@ export interface ProviderDescriptor<Module extends ProviderModule = ProviderModu
84
92
  * default, and the caller refuses the setting in words (Docker's sandbox: the server builds its image, prepareImage).
85
93
  */
86
94
  readonly defaultImage?: Partial<Record<ComputerSettingKind, string>>;
87
- /** Its built providers have prepareImage(): the image a computer starts from is made or pulled before the first create. */
95
+ /**
96
+ * Its built providers have prepareImage(), the declaration: the image a computer starts from is made or pulled before
97
+ * the first create. Settings reads this without loading the provider; the Core case provider.prepare-image holds the
98
+ * two to agree.
99
+ */
88
100
  readonly prepareImage?: boolean;
89
101
  /**
90
102
  * The server's environment variable that, when its operator sets it, names the image every computer of this provider
@@ -126,3 +138,12 @@ export interface ProviderDescriptor<Module extends ProviderModule = ProviderModu
126
138
  export declare function defineProvider<const Descriptor extends ProviderDescriptor>(descriptor: Descriptor): Descriptor;
127
139
  /** What is wrong with a value offered as a descriptor, in words; none when it is one. */
128
140
  export declare function descriptorProblems(value: unknown): string[];
141
+ /**
142
+ * The mount kinds a provider's computers take, and why not the others, with the keys `set` says the operator has set: its
143
+ * mounts, and each kind of its mountsWith whose key is set, which leaves its unmounted. What a provider made with those
144
+ * keys declares (capabilities().mount), and what a server reads to know whether that provider can mount a run's folder.
145
+ */
146
+ export declare function mountsOf(descriptor: Pick<ProviderDescriptor, "mounts" | "unmounted" | "mountsWith">, set: (name: string) => boolean): {
147
+ mounts: MountKind[];
148
+ unmounted: Unmounted;
149
+ };
@@ -33,6 +33,14 @@ export function descriptorProblems(value) {
33
33
  else if (Array.isArray(d.mounts) && entries.some(([kind]) => d.mounts?.includes(kind)))
34
34
  problems.push("unmounted names a mount kind that mounts declares");
35
35
  }
36
+ if (d.mountsWith !== undefined) {
37
+ const entries = typeof d.mountsWith === "object" && d.mountsWith !== null && !Array.isArray(d.mountsWith) ? Object.entries(d.mountsWith) : undefined;
38
+ const optional = (name) => Array.isArray(d.keys) && d.keys.some((key) => key?.name === name && key.required === false);
39
+ if (entries === undefined || entries.some(([kind, key]) => (kind !== "bind" && kind !== "archil") || typeof key !== "string" || !optional(key)))
40
+ problems.push("mountsWith maps mount kinds (bind, archil) to the name of one of its keys that is not required");
41
+ else if (entries.some(([kind]) => typeof d.unmounted?.[kind] !== "string"))
42
+ problems.push("each kind of mountsWith is in unmounted too, with why while its key is unset");
43
+ }
36
44
  if (!Array.isArray(d.network) || d.network.length === 0 || d.network.some((form) => form !== "none" && form !== "open" && form !== "allow"))
37
45
  problems.push("network is not a list of the network forms its computers make (none, open, allow)");
38
46
  if (!Array.isArray(d.capabilities) || d.capabilities.length === 0)
@@ -99,3 +107,13 @@ export function descriptorProblems(value) {
99
107
  }
100
108
  return problems;
101
109
  }
110
+ /**
111
+ * The mount kinds a provider's computers take, and why not the others, with the keys `set` says the operator has set: its
112
+ * mounts, and each kind of its mountsWith whose key is set, which leaves its unmounted. What a provider made with those
113
+ * keys declares (capabilities().mount), and what a server reads to know whether that provider can mount a run's folder.
114
+ */
115
+ export function mountsOf(descriptor, set) {
116
+ const taken = Object.entries(descriptor.mountsWith ?? {}).flatMap(([kind, key]) => (typeof key === "string" && set(key) ? [kind] : []));
117
+ const unmounted = Object.fromEntries(Object.entries(descriptor.unmounted ?? {}).filter(([kind]) => !taken.includes(kind)));
118
+ return { mounts: [...descriptor.mounts, ...taken.filter((kind) => !descriptor.mounts.includes(kind))], unmounted };
119
+ }
@@ -0,0 +1,52 @@
1
+ /** boxd's own Ubuntu 24.04 image: a computer whose spec names it starts from no snapshot. */
2
+ export declare const BOXD_DEFAULT_IMAGE = "default";
3
+ export declare const BOXD: {
4
+ readonly id: "boxd";
5
+ readonly label: "boxd";
6
+ readonly keys: readonly [{
7
+ readonly name: "BOXD_API_KEY";
8
+ readonly option: "apiKey";
9
+ readonly required: true;
10
+ }, {
11
+ readonly name: "BOXD_ORG";
12
+ readonly option: "org";
13
+ readonly required: false;
14
+ }, {
15
+ readonly name: "BOXD_REGION";
16
+ readonly option: "region";
17
+ readonly required: false;
18
+ }];
19
+ readonly metered: true;
20
+ readonly mounts: readonly [];
21
+ readonly network: readonly ["none"];
22
+ readonly capabilities: readonly [{
23
+ readonly options: {
24
+ readonly kind: "linux";
25
+ };
26
+ readonly kind: import("../protocol.js").ComputerKind;
27
+ readonly groups: import("../protocol.js").Group[];
28
+ readonly gpu?: import("../provider.js").GpuCapability;
29
+ readonly persistence?: {
30
+ keepsState: true;
31
+ resume: boolean;
32
+ };
33
+ readonly image?: string;
34
+ }, {
35
+ readonly options: {
36
+ readonly kind: "desktop";
37
+ };
38
+ readonly kind: import("../protocol.js").ComputerKind;
39
+ readonly groups: import("../protocol.js").Group[];
40
+ readonly gpu?: import("../provider.js").GpuCapability;
41
+ readonly persistence?: {
42
+ keepsState: true;
43
+ resume: boolean;
44
+ };
45
+ readonly image?: string;
46
+ }];
47
+ readonly defaultImage: {
48
+ readonly sandbox: "default";
49
+ };
50
+ readonly prepareImage: true;
51
+ readonly load: () => Promise<typeof import("../boxd.js")>;
52
+ };
@@ -0,0 +1,29 @@
1
+ // boxd's descriptor: a boxd machine (a microVM) as a sandbox or a desktop, the desktop restored from a snapshot its
2
+ // prepareImage() builds. No mount yet.
3
+ import { defineProvider } from "../descriptor.js";
4
+ import { LINUX_DESKTOP, SANDBOX } from "./shared.js";
5
+ /** boxd's own Ubuntu 24.04 image: a computer whose spec names it starts from no snapshot. */
6
+ export const BOXD_DEFAULT_IMAGE = "default";
7
+ export const BOXD = defineProvider({
8
+ id: "boxd",
9
+ label: "boxd",
10
+ keys: [
11
+ { name: "BOXD_API_KEY", option: "apiKey", required: true },
12
+ { name: "BOXD_ORG", option: "org", required: false },
13
+ { name: "BOXD_REGION", option: "region", required: false },
14
+ ],
15
+ metered: true,
16
+ mounts: [],
17
+ // None: its programs run in a network of their own (isolation.ts OWN_NETWORK_ONLY).
18
+ network: ["none"],
19
+ // Each configuration names the kind its create() options build: the provider's default is linux.
20
+ capabilities: [
21
+ { ...SANDBOX, options: { kind: "linux" } },
22
+ { ...LINUX_DESKTOP, options: { kind: "desktop" } },
23
+ ],
24
+ // A sandbox starts from boxd's own image. A desktop has no default: it starts from the snapshot its prepareImage()
25
+ // builds once in the key's org (agentrun-desktop-<hash>), boxd's own image with a stock app added.
26
+ defaultImage: { sandbox: BOXD_DEFAULT_IMAGE },
27
+ prepareImage: true,
28
+ load: () => import("../boxd.js"),
29
+ });
@@ -0,0 +1,21 @@
1
+ /** The relay's routes and rows this package speaks: the relay template's RELAY_VERSION; testConnection refuses another. */
2
+ export declare const CLOUDFLARE_RELAY_VERSION = 1;
3
+ export declare const CLOUDFLARE: {
4
+ readonly id: "cloudflare";
5
+ readonly label: "Cloudflare";
6
+ readonly keys: readonly [{
7
+ readonly name: "CLOUDFLARE_RELAY_URL";
8
+ readonly option: "relayUrl";
9
+ readonly required: true;
10
+ }, {
11
+ readonly name: "CLOUDFLARE_RELAY_TOKEN";
12
+ readonly option: "relayToken";
13
+ readonly required: true;
14
+ }];
15
+ readonly metered: true;
16
+ readonly mounts: readonly [];
17
+ readonly network: readonly ["none", "open", "allow"];
18
+ readonly capabilities: readonly [import("../kinds.js").KindCapabilities];
19
+ readonly prepareImage: true;
20
+ readonly load: () => Promise<typeof import("../cloudflare.js")>;
21
+ };
@@ -0,0 +1,29 @@
1
+ // Cloudflare's descriptor: a Linux sandbox in a Cloudflare Container (a Firecracker microVM) in the operator's own
2
+ // account, started by the relay Worker the operator deploys from packages/computer/relays/cloudflare, from the box image
3
+ // that relay was built FROM. Its containers dial the server (MachineHost facts.connect "dial"): Cloudflare has no REST
4
+ // call that starts or reaches into a container, so the relay creates, lists and deletes them, and computerd dials the
5
+ // server's attach route.
6
+ import { defineProvider } from "../descriptor.js";
7
+ import { SANDBOX } from "./shared.js";
8
+ /** The relay's routes and rows this package speaks: the relay template's RELAY_VERSION; testConnection refuses another. */
9
+ export const CLOUDFLARE_RELAY_VERSION = 1;
10
+ export const CLOUDFLARE = defineProvider({
11
+ id: "cloudflare",
12
+ label: "Cloudflare",
13
+ keys: [
14
+ { name: "CLOUDFLARE_RELAY_URL", option: "relayUrl", required: true },
15
+ { name: "CLOUDFLARE_RELAY_TOKEN", option: "relayToken", required: true },
16
+ ],
17
+ metered: true,
18
+ // None: a machine that dials takes no Archil mount yet (its helper's root steps run through exec, which it has none of).
19
+ mounts: [],
20
+ // None: its programs run in init's network of their own, their loopback alone (isolation.ts). Open and a list: their
21
+ // one way out is init's egress proxy (hosted/network.ts). The container itself always reaches out (enableInternet): it
22
+ // fetches its daemon from the server and dials it.
23
+ network: ["none", "open", "allow"],
24
+ // A linux computer alone: agentrun-dial starts init with no display.
25
+ capabilities: [SANDBOX],
26
+ // No default image: every computer starts from the box image the relay was deployed with, which prepareImage() reads.
27
+ prepareImage: true,
28
+ load: () => import("../cloudflare.js"),
29
+ });
@@ -1,6 +1,8 @@
1
1
  import type { GpuCapability } from "../provider.js";
2
- /** Why a Daytona computer takes no Archil mount: check() refuses one in these words. */
3
- export declare const DAYTONA_NO_ARCHIL = "Archil mounts don't work on Daytona yet: Archil's client hangs on its sandboxes";
2
+ /** The key that turns on a Daytona computer's Archil mount: the operator's Archil egress relay (archilEgress). */
3
+ export declare const DAYTONA_ARCHIL_EGRESS = "DAYTONA_ARCHIL_EGRESS";
4
+ /** Why a Daytona computer made with no Archil egress takes no Archil mount: check() refuses one in these words. */
5
+ export declare const DAYTONA_NO_ARCHIL = "Archil mounts don't work on Daytona's hosted cloud, where Archil's client hangs on its sandboxes; a self-hosted Daytona target takes one once its operator sets DAYTONA_ARCHIL_EGRESS";
4
6
  /** The image a Daytona computer starts from when its spec names "default": Daytona's own default snapshot. */
5
7
  export declare const DAYTONA_DEFAULT_SNAPSHOT = "default";
6
8
  /** The one region Daytona runs a GPU sandbox in, whatever the provider's target. */
@@ -58,11 +60,18 @@ export declare const DAYTONA: {
58
60
  readonly name: "DAYTONA_TARGET";
59
61
  readonly option: "target";
60
62
  readonly required: false;
63
+ }, {
64
+ readonly name: "DAYTONA_ARCHIL_EGRESS";
65
+ readonly option: "archilEgress";
66
+ readonly required: false;
61
67
  }];
62
68
  readonly metered: true;
63
69
  readonly mounts: readonly [];
64
70
  readonly unmounted: {
65
- readonly archil: "Archil mounts don't work on Daytona yet: Archil's client hangs on its sandboxes";
71
+ readonly archil: "Archil mounts don't work on Daytona's hosted cloud, where Archil's client hangs on its sandboxes; a self-hosted Daytona target takes one once its operator sets DAYTONA_ARCHIL_EGRESS";
72
+ };
73
+ readonly mountsWith: {
74
+ readonly archil: "DAYTONA_ARCHIL_EGRESS";
66
75
  };
67
76
  readonly network: readonly ["none", "open", "allow"];
68
77
  readonly capabilities: readonly [{