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

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 (48) hide show
  1. package/README.md +31 -14
  2. package/box/Dockerfile +6 -4
  3. package/box/README.md +8 -0
  4. package/box/build-daytona.py +3 -1
  5. package/box/install.sh +68 -7
  6. package/dist/attach.d.ts +46 -1
  7. package/dist/attach.js +48 -4
  8. package/dist/box-image.d.ts +2 -0
  9. package/dist/box-image.js +10 -0
  10. package/dist/computerd-linux-amd64 +0 -0
  11. package/dist/computerd-linux-arm64 +0 -0
  12. package/dist/computerd.json +2 -2
  13. package/dist/conformance/cases/provider.js +42 -26
  14. package/dist/conformance/cli.js +4 -1
  15. package/dist/conformance/daytona.d.ts +25 -0
  16. package/dist/conformance/daytona.js +26 -1
  17. package/dist/conformance/exec-stream.js +14 -6
  18. package/dist/conformance/runner.js +8 -4
  19. package/dist/conformance/sweep.d.ts +7 -2
  20. package/dist/conformance/sweep.js +17 -7
  21. package/dist/conformance/types.d.ts +21 -0
  22. package/dist/daytona.d.ts +8 -1
  23. package/dist/daytona.js +124 -101
  24. package/dist/descriptor.d.ts +22 -1
  25. package/dist/descriptor.js +18 -0
  26. package/dist/descriptors/daytona.d.ts +12 -3
  27. package/dist/descriptors/daytona.js +15 -7
  28. package/dist/descriptors/index.d.ts +8 -1
  29. package/dist/e2b.js +1 -1
  30. package/dist/host.d.ts +61 -37
  31. package/dist/hosted/framed-exec.d.ts +8 -19
  32. package/dist/hosted/framed-exec.js +21 -87
  33. package/dist/hosted/process.d.ts +2 -0
  34. package/dist/hosted/process.js +9 -2
  35. package/dist/hosted/provider.d.ts +41 -4
  36. package/dist/hosted/provider.js +289 -115
  37. package/dist/hosted/rest.d.ts +19 -0
  38. package/dist/hosted/rest.js +76 -0
  39. package/dist/hosted/scripts.d.ts +50 -0
  40. package/dist/hosted/scripts.js +116 -1
  41. package/dist/hosted/ssh-exec.d.ts +7 -6
  42. package/dist/hosted/ssh-exec.js +35 -52
  43. package/dist/index.d.ts +2 -2
  44. package/dist/index.js +2 -2
  45. package/dist/kinds.d.ts +2 -0
  46. package/dist/modal.js +21 -8
  47. package/dist/providers.d.ts +4 -2
  48. package/package.json +1 -1
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
+ }
@@ -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 [{
@@ -1,8 +1,11 @@
1
- // Daytona's descriptor: a sandbox on Daytona's cloud, with GPUs when asked; no mount of the run's folder yet.
1
+ // Daytona's descriptor: a sandbox on Daytona's cloud, with GPUs when asked; the run's folder on an Archil disk only where
2
+ // the operator gives an Archil egress relay (a self-hosted Daytona target), never on Daytona's hosted cloud.
2
3
  import { defineProvider } from "../descriptor.js";
3
4
  import { SANDBOX } from "./shared.js";
4
- /** Why a Daytona computer takes no Archil mount: check() refuses one in these words. */
5
- export const DAYTONA_NO_ARCHIL = "Archil mounts don't work on Daytona yet: Archil's client hangs on its sandboxes";
5
+ /** The key that turns on a Daytona computer's Archil mount: the operator's Archil egress relay (archilEgress). */
6
+ export const DAYTONA_ARCHIL_EGRESS = "DAYTONA_ARCHIL_EGRESS";
7
+ /** Why a Daytona computer made with no Archil egress takes no Archil mount: check() refuses one in these words. */
8
+ export 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}`;
6
9
  /** The image a Daytona computer starts from when its spec names "default": Daytona's own default snapshot. */
7
10
  export const DAYTONA_DEFAULT_SNAPSHOT = "default";
8
11
  /** The one region Daytona runs a GPU sandbox in, whatever the provider's target. */
@@ -67,13 +70,17 @@ export const DAYTONA = defineProvider({
67
70
  { name: "DAYTONA_API_KEY", option: "apiKey", required: true },
68
71
  { name: "DAYTONA_API_URL", option: "apiUrl", required: false },
69
72
  { name: "DAYTONA_TARGET", option: "target", required: false },
73
+ { name: DAYTONA_ARCHIL_EGRESS, option: "archilEgress", required: false },
70
74
  ],
71
75
  metered: true,
72
- // No mount: Archil's client (0.10.1) mounts on Daytona's container sandboxes, but nothing reads its /dev/fuse after,
73
- // so the first statx of the folder hangs, on every kernel and mount shape tried (live, 11-14), and Daytona offered
74
- // no linux-vm class to try instead. An Archil mount is refused in these words, before any request.
76
+ // No mount by default: on Daytona's hosted cloud, Archil's client (0.10.1) mounts on its container sandboxes, but
77
+ // nothing reads its /dev/fuse after, so the first statx of the folder hangs, on every kernel and mount shape tried
78
+ // (live, 11-14). An Archil mount is refused in these words, before any request. A self-hosted Daytona target whose
79
+ // sandboxes reach Archil through the operator's egress relay mounts it (live, 11-14): the operator sets
80
+ // DAYTONA_ARCHIL_EGRESS, and a provider made with it takes an Archil mount (mountsOf).
75
81
  mounts: [],
76
82
  unmounted: { archil: DAYTONA_NO_ARCHIL },
83
+ mountsWith: { archil: DAYTONA_ARCHIL_EGRESS },
77
84
  // None: its programs run in a network of their own, their loopback alone (isolation.ts), and the sandbox is made with
78
85
  // networkBlockAll. Open and a list: the sandbox is not blocked (the account's tier may still limit where it goes), and
79
86
  // its programs' one way out is init's egress proxy, which reaches the public internet alone, and with a list its hosts
@@ -82,7 +89,8 @@ export const DAYTONA = defineProvider({
82
89
  // A linux computer, with GPUs when asked.
83
90
  capabilities: [{ ...SANDBOX, gpu: DAYTONA_GPU }],
84
91
  defaultImage: { sandbox: DAYTONA_DEFAULT_SNAPSHOT },
85
- // The operator's own snapshot for every Daytona computer, named here; the default snapshot stands while unset.
92
+ // The operator's own snapshot for every Daytona computer, named here; the default snapshot stands while unset. A
93
+ // computer with an Archil mount needs a snapshot of box/Dockerfile (box/build-daytona.py prints its name).
86
94
  imageEnv: "AGENTRUN_DAYTONA_SNAPSHOT",
87
95
  load: () => import("../daytona.js"),
88
96
  });
@@ -46,11 +46,18 @@ export declare const DESCRIPTORS: readonly [{
46
46
  readonly name: "DAYTONA_TARGET";
47
47
  readonly option: "target";
48
48
  readonly required: false;
49
+ }, {
50
+ readonly name: "DAYTONA_ARCHIL_EGRESS";
51
+ readonly option: "archilEgress";
52
+ readonly required: false;
49
53
  }];
50
54
  readonly metered: true;
51
55
  readonly mounts: readonly [];
52
56
  readonly unmounted: {
53
- readonly archil: "Archil mounts don't work on Daytona yet: Archil's client hangs on its sandboxes";
57
+ 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";
58
+ };
59
+ readonly mountsWith: {
60
+ readonly archil: "DAYTONA_ARCHIL_EGRESS";
54
61
  };
55
62
  readonly network: readonly ["none", "open", "allow"];
56
63
  readonly capabilities: readonly [{
package/dist/e2b.js CHANGED
@@ -122,7 +122,7 @@ class E2BHost {
122
122
  maxLifetimeMs: PRO_MAX_MS,
123
123
  arch: "amd64",
124
124
  vendorAgentPorts: [ENVD_PORT],
125
- // The box template has xfwm4 (box/Dockerfile), as E2B Desktop's has: the apps an agent opens are framed and focused.
125
+ // The box template has xfwm4 (box/install.sh's desktop step), as E2B Desktop's has: the apps an agent opens are framed and focused.
126
126
  windowManager: true,
127
127
  // System paths whose permissions E2B's template build sets wider than root's, on its templates and ours alike.
128
128
  rootOnly: ROOT_ONLY,