@parcha/agentrun-computer 0.1.0-beta.34 → 0.1.0-beta.36

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 (107) hide show
  1. package/README.md +251 -46
  2. package/box/Dockerfile +3 -1
  3. package/box/agentrun-archil +59 -7
  4. package/box/build-daytona.py +20 -4
  5. package/dist/browser.d.ts +73 -23
  6. package/dist/browser.js +141 -17
  7. package/dist/browserbase.d.ts +48 -25
  8. package/dist/browserbase.js +176 -29
  9. package/dist/chrome.d.ts +3 -4
  10. package/dist/chrome.js +6 -11
  11. package/dist/computerd-linux-amd64 +0 -0
  12. package/dist/computerd-linux-arm64 +0 -0
  13. package/dist/conformance/browserbase.js +1 -1
  14. package/dist/conformance/cases/provider.js +78 -3
  15. package/dist/conformance/daytona.d.ts +4 -0
  16. package/dist/conformance/daytona.js +7 -1
  17. package/dist/conformance/e2b.js +2 -1
  18. package/dist/conformance/fixture.js +24 -2
  19. package/dist/conformance/kernel.js +1 -1
  20. package/dist/conformance/kind.js +2 -1
  21. package/dist/conformance/{local.d.ts → local-chrome.d.ts} +7 -7
  22. package/dist/conformance/{local.js → local-chrome.js} +11 -11
  23. package/dist/conformance/orgo.d.ts +11 -5
  24. package/dist/conformance/orgo.js +37 -8
  25. package/dist/conformance/phone-harness.js +2 -1
  26. package/dist/conformance/report.js +3 -2
  27. package/dist/conformance/runner.js +25 -7
  28. package/dist/conformance/types.d.ts +21 -8
  29. package/dist/conformance/types.js +10 -0
  30. package/dist/conformance/windows-fixture.d.ts +1 -0
  31. package/dist/conformance/windows-fixture.js +37 -0
  32. package/dist/daytona.d.ts +16 -35
  33. package/dist/daytona.js +87 -95
  34. package/dist/descriptor.d.ts +116 -0
  35. package/dist/descriptor.js +92 -0
  36. package/dist/descriptors/browserbase.d.ts +25 -0
  37. package/dist/descriptors/browserbase.js +20 -0
  38. package/dist/descriptors/daytona.d.ts +83 -0
  39. package/dist/descriptors/daytona.js +81 -0
  40. package/dist/descriptors/docker.d.ts +12 -0
  41. package/dist/descriptors/docker.js +17 -0
  42. package/dist/descriptors/e2b.d.ts +22 -0
  43. package/dist/descriptors/e2b.js +19 -0
  44. package/dist/descriptors/index.d.ts +256 -0
  45. package/dist/descriptors/index.js +19 -0
  46. package/dist/descriptors/kernel.d.ts +21 -0
  47. package/dist/descriptors/kernel.js +17 -0
  48. package/dist/descriptors/local-chrome.d.ts +17 -0
  49. package/dist/descriptors/local-chrome.js +21 -0
  50. package/dist/descriptors/modal.d.ts +54 -0
  51. package/dist/descriptors/modal.js +48 -0
  52. package/dist/descriptors/orgo.d.ts +99 -0
  53. package/dist/descriptors/orgo.js +49 -0
  54. package/dist/descriptors/phone-harness.d.ts +33 -0
  55. package/dist/descriptors/phone-harness.js +23 -0
  56. package/dist/descriptors/shared.d.ts +7 -0
  57. package/dist/descriptors/shared.js +6 -0
  58. package/dist/desktop.d.ts +4 -4
  59. package/dist/desktop.js +4 -4
  60. package/dist/docker/egress.d.ts +5 -4
  61. package/dist/docker/egress.js +7 -6
  62. package/dist/docker/image.js +17 -15
  63. package/dist/docker/inspect.d.ts +147 -0
  64. package/dist/docker/inspect.js +335 -0
  65. package/dist/docker.d.ts +6 -6
  66. package/dist/docker.js +53 -47
  67. package/dist/drift.d.ts +3 -145
  68. package/dist/drift.js +5 -334
  69. package/dist/e2b.d.ts +2 -8
  70. package/dist/e2b.js +17 -23
  71. package/dist/index.d.ts +9 -12
  72. package/dist/index.js +14 -12
  73. package/dist/isolation.js +2 -2
  74. package/dist/janitor.d.ts +20 -2
  75. package/dist/janitor.js +67 -19
  76. package/dist/kernel.d.ts +19 -29
  77. package/dist/kernel.js +110 -32
  78. package/dist/kinds.d.ts +59 -34
  79. package/dist/kinds.js +19 -117
  80. package/dist/labels.d.ts +20 -0
  81. package/dist/labels.js +62 -1
  82. package/dist/{local.d.ts → local-chrome.d.ts} +8 -9
  83. package/dist/{local.js → local-chrome.js} +26 -19
  84. package/dist/local-supervisor.d.ts +3 -3
  85. package/dist/local-supervisor.js +3 -3
  86. package/dist/modal.d.ts +6 -25
  87. package/dist/modal.js +86 -88
  88. package/dist/mount-archil.d.ts +25 -3
  89. package/dist/mount-archil.js +43 -12
  90. package/dist/orgo-channel.js +16 -13
  91. package/dist/orgo-desktop.d.ts +162 -0
  92. package/dist/orgo-desktop.js +1856 -0
  93. package/dist/orgo-names.d.ts +178 -0
  94. package/dist/orgo-names.js +287 -0
  95. package/dist/orgo.d.ts +34 -20
  96. package/dist/orgo.js +424 -173
  97. package/dist/phone-harness.d.ts +7 -12
  98. package/dist/phone-harness.js +70 -54
  99. package/dist/protocol.d.ts +5 -0
  100. package/dist/provider.d.ts +153 -10
  101. package/dist/provider.js +48 -1
  102. package/dist/providers.d.ts +23 -24
  103. package/dist/providers.js +14 -17
  104. package/dist/result.d.ts +11 -1
  105. package/dist/result.js +11 -0
  106. package/dist/test-connection.js +2 -2
  107. package/package.json +42 -2
package/dist/modal.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { KindCapabilities } from "./kinds.js";
2
2
  import { type MountKind } from "./mount.js";
3
3
  import { type ProviderNote } from "./mount-archil.js";
4
- import { type AttachedComputer, type CallContext, type ComputerCapabilities, type ComputerConnection, type ComputerInfo, type ComputerProvider, type ComputerRef, type ComputerSpec, type CreatedComputer, type GpuCapability, type NetworkForm, type NetworkPolicy, type NetworkSpec, type Refusal } from "./provider.js";
4
+ import { type AttachedComputer, type CallContext, type ComputerCapabilities, type ComputerConnection, type ComputerInfo, type ComputerProvider, type ComputerRef, type ComputerSpec, type CreatedComputer, type NetworkPolicy, type NetworkSpec, type Refusal, type ReleaseHow } from "./provider.js";
5
5
  import { type Result } from "./result.js";
6
6
  import { type ScreenWatch, type ScreenWatchHandlers, type WatchOptions } from "./screen-watch.js";
7
7
  /** The App sandboxes are made in (modal-client@64880502:js/src/app.ts:32-61). */
@@ -142,29 +142,10 @@ export interface ModalProviderOptions {
142
142
  }
143
143
  /** The mount kinds a Modal computer takes, as capabilities().mount declares them: the run's folder on an Archil disk. */
144
144
  export declare const MOUNT: readonly MountKind[];
145
- /** The network a Modal computer's programs get: none, a network of their own (isolation.ts OWN_NETWORK_ONLY). */
146
- export declare const NETWORK: readonly NetworkForm[];
147
145
  /** The runtime a Modal sandbox runs under: vm, or gvisor for a GPU computer (Modal offers GPUs on gVisor only). */
148
146
  export type ModalRuntime = "vm" | "gvisor";
149
- /**
150
- * The GPU types Modal takes, by its own names (guide/gpu, 11-10): "A100" is the 40 GB one, "A100-40GB" its explicit
151
- * name. Its "H100!" and "B200+" variants (no upgrade to an H200; a B200 or B300) are not offered: what a computer gets
152
- * should be what it asked for.
153
- */
154
- export declare const MODAL_GPU_TYPES: readonly ["T4", "L4", "A10", "L40S", "A100", "A100-40GB", "A100-80GB", "RTX-PRO-6000", "H100", "H200", "B200", "B300"];
155
- /** The most GPUs Modal gives one container: 8 (guide/gpu; an A10 container takes at most 4, which Modal refuses in words past). */
156
- export declare const MODAL_GPU_MAX = 8;
157
- /**
158
- * The GPUs Modal offers, as capabilities().gpu and CAPABILITIES declare them: on gVisor, Modal's one GPU runtime;
159
- * preemptible, as Modal may end a GPU container to free capacity; no mount yet, the Archil client's FUSE mount not
160
- * being proven on gVisor; and the loopback fence made inside a user namespace, as gVisor's root may not make a network
161
- * namespace itself (a live probe, 11-11: unshare -n refused, unshare -Urn allowed).
162
- */
163
- export declare const MODAL_GPU: Readonly<GpuCapability>;
164
- /** The machine kind, groups and GPUs of its one configuration: a linux computer, with GPUs when asked. */
147
+ /** The machine kind, groups and GPUs of its one configuration (its descriptor's): a linux computer, with GPUs when asked. */
165
148
  export declare const CAPABILITIES: readonly KindCapabilities[];
166
- /** A registry tag for linux/amd64 that Modal can pull: the default when a setting names no image. */
167
- export declare const MODAL_DEFAULT_IMAGE = "debian:bookworm-slim";
168
149
  /** The SDK's default server (modal-client@64880502:js/src/config.ts:143). */
169
150
  export declare const MODAL_DEFAULT_SERVER_URL = "https://api.modal.com:443";
170
151
  /** What modalClient gives the SDK's ModalClient: the token, explicitly, so the SDK fills none of it in. */
@@ -309,9 +290,9 @@ export declare class ModalProvider implements ComputerProvider {
309
290
  */
310
291
  list(labels: Record<string, string>, { signal }?: CallContext): Promise<Result<ComputerInfo[]>>;
311
292
  /**
312
- * Modal reads no policy back. Open is open, nothing being wider; none is read back by the probe from inside, and is
313
- * another network in words when any of its addresses answered (an address that only accepted, and sent nothing back,
314
- * leaves it none). A change is refused: it is fixed at create.
293
+ * Modal reads no policy back. A computer here is made with none, read back by the probe from inside, and is another
294
+ * network in words when any of its addresses answered (an address that only accepted, and sent nothing back, leaves it
295
+ * none). A change is refused: it is fixed at create.
315
296
  */
316
297
  network(ref: ComputerRef, policy?: NetworkSpec, { signal }?: CallContext): Promise<Result<NetworkPolicy>>;
317
298
  /**
@@ -325,5 +306,5 @@ export declare class ModalProvider implements ComputerProvider {
325
306
  * loses nothing (every call that changed it synced, and the next claim revokes the hold), so it is said through
326
307
  * onNote, and the release succeeds once the sandbox is gone.
327
308
  */
328
- release(ref: ComputerRef, how: "stop" | "delete", { signal }?: CallContext): Promise<Result<void>>;
309
+ release(ref: ComputerRef, how: ReleaseHow, { signal }?: CallContext): Promise<Result<void>>;
329
310
  }
package/dist/modal.js CHANGED
@@ -6,44 +6,28 @@ import { readFileSync } from "node:fs";
6
6
  import { Readable, Writable } from "node:stream";
7
7
  import { fileURLToPath } from "node:url";
8
8
  import { DaemonClient } from "./client.js";
9
+ import { MODAL, MODAL_DEFAULT_IMAGE, MODAL_GPU } from "./descriptors/modal.js";
9
10
  import { COMPUTER_LABEL, DAEMON_IN_COMPUTER, DEADLINE_LABEL, DEFAULT_CPUS, DEFAULT_MEMORY_MB, helloDrift, probeNetworkDrift, probeNotes, probeReportOf, WORK, } from "./drift.js";
10
11
  import { OWN_NETWORK_ONLY, probeOwnNetworkDrift, TOOL_USER } from "./isolation.js";
11
12
  import { releaseOlder } from "./janitor.js";
12
13
  import { EPOCH_LABEL, epochOf, RUN_LABEL } from "./labels.js";
13
- import { checkMount, readBackOf } from "./mount.js";
14
+ import { checkMount } from "./mount.js";
14
15
  import { ARCHIL_HELPER, ARCHIL_MOUNT_LABEL, ARCHIL_TOOL_UID, archilMount, archilRefusals, archilRelease, claimEpoch, mountDrift, readArchilMount, recordedArchil as recordedArchilOf, syncingClient, } from "./mount-archil.js";
15
- import { checkGpu, checkLifetime, } from "./provider.js";
16
- import { fail, ok } from "./result.js";
16
+ import { checkGpu, checkTenure, runLifetimeMs, } from "./provider.js";
17
+ import { failFor, ok, vendorFail } from "./result.js";
17
18
  import { daemonWatch } from "./screen-watch.js";
18
19
  import { connectionError } from "./test-connection.js";
19
20
  import { waitUntil } from "./wait.js";
21
+ /** This module's failures: one with code vendor names Modal. */
22
+ const fail = failFor("modal");
20
23
  /** The mount kinds a Modal computer takes, as capabilities().mount declares them: the run's folder on an Archil disk. */
21
- export const MOUNT = ["archil"];
22
- /** The network a Modal computer's programs get: none, a network of their own (isolation.ts OWN_NETWORK_ONLY). */
23
- export const NETWORK = ["none"];
24
- /**
25
- * The GPU types Modal takes, by its own names (guide/gpu, 11-10): "A100" is the 40 GB one, "A100-40GB" its explicit
26
- * name. Its "H100!" and "B200+" variants (no upgrade to an H200; a B200 or B300) are not offered: what a computer gets
27
- * should be what it asked for.
28
- */
29
- export const MODAL_GPU_TYPES = ["T4", "L4", "A10", "L40S", "A100", "A100-40GB", "A100-80GB", "RTX-PRO-6000", "H100", "H200", "B200", "B300"];
30
- /** The most GPUs Modal gives one container: 8 (guide/gpu; an A10 container takes at most 4, which Modal refuses in words past). */
31
- export const MODAL_GPU_MAX = 8;
32
- /**
33
- * The GPUs Modal offers, as capabilities().gpu and CAPABILITIES declare them: on gVisor, Modal's one GPU runtime;
34
- * preemptible, as Modal may end a GPU container to free capacity; no mount yet, the Archil client's FUSE mount not
35
- * being proven on gVisor; and the loopback fence made inside a user namespace, as gVisor's root may not make a network
36
- * namespace itself (a live probe, 11-11: unshare -n refused, unshare -Urn allowed).
37
- */
38
- export const MODAL_GPU = Object.freeze({ types: [...MODAL_GPU_TYPES], max: MODAL_GPU_MAX, isolation: "gvisor", preemptible: true, mounts: [], fence: "userns-netns" });
39
- /** A copy of MODAL_GPU, so no caller can change the provider's own. */
24
+ export const MOUNT = MODAL.mounts;
25
+ /** A copy of its descriptor's MODAL_GPU, so no caller can change the provider's own. */
40
26
  const modalGpuCapability = () => ({ ...MODAL_GPU, types: [...MODAL_GPU.types], mounts: [] });
41
27
  /** A GPU as the SDK takes it: the type, then :count past one ("T4", "H100:8"). */
42
28
  const modalGpu = ({ type, count }) => (count === 1 ? type : `${type}:${count}`);
43
- /** The machine kind, groups and GPUs of its one configuration: a linux computer, with GPUs when asked. */
44
- export const CAPABILITIES = [{ kind: "linux", groups: ["exec", "files", "processes"], gpu: modalGpuCapability() }];
45
- /** A registry tag for linux/amd64 that Modal can pull: the default when a setting names no image. */
46
- export const MODAL_DEFAULT_IMAGE = "debian:bookworm-slim";
29
+ /** The machine kind, groups and GPUs of its one configuration (its descriptor's): a linux computer, with GPUs when asked. */
30
+ export const CAPABILITIES = MODAL.capabilities;
47
31
  /** The SDK's default server (modal-client@64880502:js/src/config.ts:143). */
48
32
  export const MODAL_DEFAULT_SERVER_URL = "https://api.modal.com:443";
49
33
  /** Not a literal, so no type checker or bundler resolves the SDK from this package. */
@@ -273,6 +257,8 @@ const SPEC_FIELDS = new Set(["image", "lifetimeMs", "network", "cpus", "memoryMb
273
257
  const NUL = "a NUL byte cannot be passed to Modal";
274
258
  const FIXED = "a Modal computer's network is fixed at create: Modal cannot update the policy of a sandbox made with blockNetwork, and updates only an allowlist set at create; create a new computer";
275
259
  const STOP = "Modal has no stop that keeps a sandbox: terminate is a sandbox's only end, and a sandbox that has finished cannot run again; release it with delete";
260
+ /** The runtime a computer runs on: gVisor, Modal's one GPU runtime, exactly when it has a GPU; a VM otherwise. */
261
+ const runtimeOf = (recorded) => (recorded.gpu === undefined ? "vm" : "gvisor");
276
262
  const isNumber = (value) => typeof value === "number" && Number.isFinite(value);
277
263
  const isWhole = (value) => typeof value === "number" && Number.isSafeInteger(value);
278
264
  const show = (value) => (value === undefined ? "nothing" : JSON.stringify(value));
@@ -317,7 +303,7 @@ function codeOf(error) {
317
303
  // TaskExecStart, when its command, init, has exited). Gone, so create waits to read why.
318
304
  if (code === 9)
319
305
  return "gone";
320
- return "modal";
306
+ return "vendor";
321
307
  }
322
308
  /** Settles with the promise's result, or a timeout or abort in words once ms pass or signal aborts. */
323
309
  function race(promise, what, ms, signal) {
@@ -449,32 +435,41 @@ function recordedOf(tags) {
449
435
  }
450
436
  return `spec: the tag ${SPEC_TAG} reads ${show(tags[SPEC_TAG])}, not the spec create writes`;
451
437
  }
452
- /** The network a computer was created with, as list reports it: a tag only the host's token writes. */
438
+ /** The network a computer was created with, as list reports it: none, the one this provider makes, where the spec tag
439
+ * (a tag only the host's token writes) is create's. */
453
440
  function recordedNetwork(tags) {
454
- const recorded = recordedOf(tags);
455
- if (typeof recorded !== "string" && (recorded.network === "none" || recorded.network === "open"))
456
- return recorded.network;
457
- return { other: `the tag ${SPEC_TAG} names no network this provider makes` };
441
+ if (typeof recordedOf(tags) !== "string")
442
+ return "none";
443
+ return { other: `the tag ${SPEC_TAG} is not the spec create writes, so the computer's network is not known` };
458
444
  }
459
445
  /**
460
446
  * The Archil mount a computer's spec tag records (recordedArchilOf, shared), or undefined when it records none: the
461
- * tag's mount, under the epoch the tag recorded it at, which must be the label's.
447
+ * tag's source, its folder the recorded agent's for the run label's run, exclusive, under the epoch the tag recorded it
448
+ * at, which must be the label's.
462
449
  */
463
450
  function recordedArchil(tags) {
464
451
  const recorded = recordedOf(tags);
465
452
  if (typeof recorded === "string" || recorded.mount === undefined)
466
453
  return undefined;
467
454
  const read = epochOf(tags);
468
- const { kind, disk, region, folder, epoch: was } = (recorded.mount ?? {});
469
- if (kind !== "archil" || typeof disk !== "string" || typeof region !== "string" || typeof folder !== "string") {
455
+ const { disk, region, agent, epoch: was } = (recorded.mount ?? {});
456
+ const run = tags[RUN_LABEL];
457
+ if (typeof disk !== "string" || typeof region !== "string" || typeof agent !== "string" || run === undefined) {
470
458
  return recordedArchilOf(tags, { other: `the tag ${SPEC_TAG} records a mount this provider never makes` });
471
459
  }
472
- const mount = { kind, disk, region, folder };
460
+ const mount = { kind: "archil", disk, region, folder: `agents/${agent}/runs/${run}/work` };
473
461
  if (read.ok && was !== read.value) {
474
462
  return recordedArchilOf(tags, { mount, other: `the tag ${SPEC_TAG} records the mount under epoch ${show(was)}, yet the label ${EPOCH_LABEL} reads ${read.value}` });
475
463
  }
476
464
  return recordedArchilOf(tags, { mount });
477
465
  }
466
+ /** Modal holds a sandbox's tags, their names and values together, to 512 bytes: a create past it is refused at Modal
467
+ * ("a sandbox's cumulative tags size (533 bytes) cannot exceed 512 bytes", 11-12). */
468
+ const MAX_TAG_BYTES = 512;
469
+ /** The <agent> of an Archil folder agents/<agent>/runs/<run>/work, the shape check() holds it to. */
470
+ const folderAgent = (folder) => folder.split("/")[1];
471
+ /** The bytes Modal counts of `tags`: every name and value, in UTF-8. */
472
+ const tagBytes = (tags) => Object.entries(tags).reduce((sum, [key, value]) => sum + Buffer.byteLength(key) + Buffer.byteLength(value), 0);
478
473
  /** Every way the probe's report differs from what the computer should be. */
479
474
  function probeDrift(probe, expected) {
480
475
  const found = [];
@@ -589,7 +584,7 @@ export class ModalProvider {
589
584
  return {
590
585
  kind: "linux",
591
586
  lifetime: "vendor",
592
- network: [...NETWORK],
587
+ network: [...MODAL.network],
593
588
  networkReadBack: false,
594
589
  isolation: "vm",
595
590
  os: "linux",
@@ -615,13 +610,13 @@ export class ModalProvider {
615
610
  const refusals = [];
616
611
  const refuse = (field, message) => refusals.push({ field, message });
617
612
  const given = (typeof spec === "object" && spec !== null ? spec : {});
618
- const { image, lifetimeMs, network, cpus, memoryMb, pids, labels, workdir, user, mount } = given;
613
+ const { image, network, cpus, memoryMb, pids, labels, workdir, user, mount } = given;
619
614
  if (typeof image !== "string" || image.trim() === "" || image.startsWith("-") || /\s/.test(image)) {
620
615
  refuse("image", `an image is required: a registry tag for linux/amd64 that Modal can pull, such as ${MODAL_DEFAULT_IMAGE}`);
621
616
  }
622
617
  else if (image.includes("\0"))
623
618
  refuse("image", NUL);
624
- refusals.push(...checkLifetime(lifetimeMs, this.capabilities()));
619
+ refusals.push(...checkTenure(given, this.capabilities(), "Modal"));
625
620
  if (network === "open" || (typeof network === "object" && network !== null && "allow" in network))
626
621
  refuse("network", OWN_NETWORK_ONLY);
627
622
  else if (network !== "none")
@@ -662,8 +657,34 @@ export class ModalProvider {
662
657
  continue;
663
658
  refuse(field, `a Modal computer does not support ${field}`);
664
659
  }
660
+ // What create would tag the sandbox with, its name and deadline as long as create's always are, within Modal's bound.
661
+ if (refusals.length === 0) {
662
+ const { tags } = this.#tags(spec, "computer-000000000000", new Date(0).toISOString());
663
+ const bytes = tagBytes(tags);
664
+ if (bytes > MAX_TAG_BYTES) {
665
+ const sizes = Object.entries(tags).map(([key, value]) => `${key} ${Buffer.byteLength(key) + Buffer.byteLength(value)}`).join(", ");
666
+ refuse(spec.mount === undefined ? "labels" : "mount", `a Modal sandbox's tags come to at most ${MAX_TAG_BYTES} bytes, names and values together, and this computer's would come to ${bytes} (${sizes}): give a shorter image, mount folder or labels`);
667
+ }
668
+ }
665
669
  return refusals;
666
670
  }
671
+ /** What create records of `spec` in its spec tag, and the sandbox's tags: the caller's labels, then this provider's own. */
672
+ #tags(spec, name, deadline) {
673
+ const mount = spec.mount?.kind === "archil" ? spec.mount : undefined;
674
+ const recorded = {
675
+ image: spec.image,
676
+ // An Archil computer's tools run as the tool user alone.
677
+ user: mount === undefined ? (userOf(spec.user) ?? this.#user) : ARCHIL_USER,
678
+ cpus: spec.cpus ?? DEFAULT_CPUS,
679
+ memoryMb: spec.memoryMb ?? DEFAULT_MEMORY_MB,
680
+ workdir: spec.workdir ?? WORK,
681
+ // The folder's agent and the claim's epoch: check() held the folder's run and the epoch to the labels before an
682
+ // Archil spec gets here.
683
+ ...(mount === undefined ? {} : { mount: { disk: mount.disk, region: mount.region, agent: folderAgent(mount.folder), epoch: claimEpoch(spec.labels) } }),
684
+ ...(spec.gpu === undefined ? {} : { gpu: { type: spec.gpu.type, count: spec.gpu.count } }),
685
+ };
686
+ return { recorded, tags: { ...spec.labels, [COMPUTER_LABEL]: "1", [NAME_TAG]: name, [DEADLINE_LABEL]: deadline, [SPEC_TAG]: JSON.stringify(recorded) } };
687
+ }
667
688
  async create(spec, { signal } = {}) {
668
689
  const refusals = this.check(spec);
669
690
  if (refusals.length > 0)
@@ -685,26 +706,11 @@ export class ModalProvider {
685
706
  if (!app.ok)
686
707
  return app;
687
708
  const name = `computer-${randomBytes(6).toString("hex")}`;
688
- const deadline = new Date(Date.now() + spec.lifetimeMs).toISOString();
709
+ const deadline = new Date(Date.now() + runLifetimeMs(spec)).toISOString();
689
710
  // An Archil mount is made under the run's claim (check() held the spec to both labels), for the tool user alone.
690
711
  const archil = spec.mount?.kind === "archil" ? { mount: spec.mount, run: spec.labels?.[RUN_LABEL], epoch: claimEpoch(spec.labels) } : undefined;
691
- const user = archil === undefined ? (userOf(spec.user) ?? this.#user) : ARCHIL_USER;
692
- const workdir = spec.workdir ?? WORK;
693
- const cpus = spec.cpus ?? DEFAULT_CPUS;
694
- const memoryMb = spec.memoryMb ?? DEFAULT_MEMORY_MB;
695
- const recorded = {
696
- image: spec.image,
697
- user,
698
- network: spec.network,
699
- cpus,
700
- memoryMb,
701
- workdir,
702
- // Modal offers GPUs on gVisor only: a GPU computer's runtime, read back by the probe's kernel like a VM's.
703
- runtime: spec.gpu === undefined ? "vm" : "gvisor",
704
- ...(archil === undefined ? {} : { mount: readBackOf(archil.mount, archil.epoch) }),
705
- ...(spec.gpu === undefined ? {} : { gpu: { type: spec.gpu.type, count: spec.gpu.count } }),
706
- };
707
- const tags = { ...spec.labels, [COMPUTER_LABEL]: "1", [NAME_TAG]: name, [DEADLINE_LABEL]: deadline, [SPEC_TAG]: JSON.stringify(recorded) };
712
+ const { recorded, tags } = this.#tags(spec, name, deadline);
713
+ const { user, workdir, cpus, memoryMb } = recorded;
708
714
  // With daemonImage the daemon comes in as a layer of the computer's own image, there before the command starts.
709
715
  // Without, the command is the entrypoint, which waits for the upload below. Either way the computer needs no
710
716
  // network to get it. HOME is a directory init gives the computer's user.
@@ -736,11 +742,12 @@ export class ModalProvider {
736
742
  : modalCommands({ deadline, user, waitSeconds: Math.ceil(waitMs / 1000), home: WORK, ...(gate === undefined ? {} : { gate }) }).entrypoint;
737
743
  const cpuLimit = cpus / CPUS_PER_CORE;
738
744
  const params = {
739
- runtime: recorded.runtime,
745
+ // Modal offers GPUs on gVisor only: a GPU computer's runtime, read back by the probe's kernel like a VM's.
746
+ runtime: runtimeOf(recorded),
740
747
  ...(spec.gpu === undefined ? {} : { gpu: modalGpu(spec.gpu) }),
741
748
  command,
742
749
  // Modal ends the sandbox at its timeout: the lifetime, in the whole seconds the SDK takes.
743
- timeoutMs: Math.ceil(spec.lifetimeMs / 1000) * 1000,
750
+ timeoutMs: Math.ceil(runLifetimeMs(spec) / 1000) * 1000,
744
751
  workdir,
745
752
  cpu: Math.min(CPU_REQUEST, cpuLimit),
746
753
  cpuLimit,
@@ -947,14 +954,14 @@ export class ModalProvider {
947
954
  const found = [
948
955
  ...tagDrift(tags, read.value),
949
956
  ...helloDrift(inside.value.hello, this.#expected()),
950
- ...probeDrift(inside.value.probe, { user: recorded.user, network: recorded.network, runtime: recorded.runtime }),
957
+ ...probeDrift(inside.value.probe, { user: recorded.user, network: "none", runtime: runtimeOf(recorded) }),
951
958
  ...(archil === undefined ? [] : mountDrift(archil.expected, inside.value.mount)),
952
959
  ];
953
960
  if (found.length > 0)
954
961
  return fail("refused", `it did not match its spec: ${found.join("; ")}`);
955
962
  // Which way init fenced its programs, as hello read it back: said once a way other than the plain one was taken.
956
- const fence = inside.value.hello.fence === "userns-netns" ? [`fence: userns-netns: init made its programs' network namespace inside a user namespace of its own, as root on ${recorded.runtime} may not make one itself`] : [];
957
- return ok([...probeNotes(inside.value.probe, recorded.network), ...fence]);
963
+ const fence = inside.value.hello.fence === "userns-netns" ? [`fence: userns-netns: init made its programs' network namespace inside a user namespace of its own, as root on ${runtimeOf(recorded)} may not make one itself`] : [];
964
+ return ok([...probeNotes(inside.value.probe, "none"), ...fence]);
958
965
  }
959
966
  /** One connection's hello and the probe through it, and an Archil computer's mount read back, the connection closed after. */
960
967
  async #inside(sandbox, name, signal, patient = false, archil) {
@@ -1144,7 +1151,7 @@ export class ModalProvider {
1144
1151
  return fail("timeout", `the daemon in ${name} did not answer hello within ${seconds(totalMs)}`);
1145
1152
  if (hello.error.code !== "gone")
1146
1153
  return hello;
1147
- return { ...fail("modal", `cannot reach the daemon in ${name}: ${stderr.trim() || hello.error.message}`), notListening: true };
1154
+ return { ...vendorFail("modal", `cannot reach the daemon in ${name}: ${stderr.trim() || hello.error.message}`), notListening: true };
1148
1155
  }
1149
1156
  return ok({ client, hello: hello.value, close });
1150
1157
  }
@@ -1206,12 +1213,8 @@ export class ModalProvider {
1206
1213
  if (typeof recorded === "string")
1207
1214
  found.push(recorded);
1208
1215
  else {
1209
- // gvisor exactly for a GPU computer, vm for every other: anything else this provider never makes.
1210
- const runtime = recorded.gpu === undefined ? "vm" : "gvisor";
1211
- if (recorded.runtime !== runtime)
1212
- found.push(`runtime: the tag ${SPEC_TAG} says ${show(recorded.runtime)}; this provider makes ${runtime} computers ${recorded.gpu === undefined ? "with no GPU" : "with a GPU"}`);
1213
- const { image, network, cpus, memoryMb, workdir, user, gpu } = recorded;
1214
- const refusals = this.check({ image, lifetimeMs: 1, network, cpus, memoryMb, workdir, user, ...(gpu === undefined ? {} : { gpu }) });
1216
+ const { image, cpus, memoryMb, workdir, user, gpu } = recorded;
1217
+ const refusals = this.check({ image, lifetimeMs: 1, network: "none", cpus, memoryMb, workdir, user, ...(gpu === undefined ? {} : { gpu }) });
1215
1218
  found.push(...refusals.map(({ field, message }) => `${field}: ${message}, as recorded at create`));
1216
1219
  // No exec in a computer whose user is root: the bridge would run what that user could have replaced.
1217
1220
  if (isRootUser(user))
@@ -1224,14 +1227,15 @@ export class ModalProvider {
1224
1227
  const { hello, probe, mount } = inside.value;
1225
1228
  found.push(...helloDrift(hello, this.#expected()));
1226
1229
  if (typeof recorded !== "string")
1227
- found.push(...probeDrift(probe, { user: recorded.user, network: recorded.network, runtime: recorded.runtime }));
1230
+ found.push(...probeDrift(probe, { user: recorded.user, network: "none", runtime: runtimeOf(recorded) }));
1228
1231
  // The mount read back from inside is the one the spec tag records, under the computer's epoch label.
1229
1232
  if (archil !== undefined)
1230
1233
  found.push(...mountDrift(archil.expected, mount));
1231
1234
  if (found.length > 0 || typeof recorded === "string" || deadline === undefined) {
1232
1235
  return fail("refused", `the computer ${name} does not match this provider, so attach refuses it and it is left as it is: ${found.join("; ")}`);
1233
1236
  }
1234
- const { image, network, cpus, memoryMb, workdir, gpu } = recorded;
1237
+ const { image, cpus, memoryMb, workdir, gpu } = recorded;
1238
+ const network = "none";
1235
1239
  const notes = probeNotes(probe, network);
1236
1240
  return ok({
1237
1241
  ...ref,
@@ -1316,9 +1320,9 @@ export class ModalProvider {
1316
1320
  return ok(infos);
1317
1321
  }
1318
1322
  /**
1319
- * Modal reads no policy back. Open is open, nothing being wider; none is read back by the probe from inside, and is
1320
- * another network in words when any of its addresses answered (an address that only accepted, and sent nothing back,
1321
- * leaves it none). A change is refused: it is fixed at create.
1323
+ * Modal reads no policy back. A computer here is made with none, read back by the probe from inside, and is another
1324
+ * network in words when any of its addresses answered (an address that only accepted, and sent nothing back, leaves it
1325
+ * none). A change is refused: it is fixed at create.
1322
1326
  */
1323
1327
  async network(ref, policy, { signal } = {}) {
1324
1328
  const problem = refProblem(ref);
@@ -1334,20 +1338,14 @@ export class ModalProvider {
1334
1338
  const recorded = recordedNetwork(found.value.tags);
1335
1339
  if (typeof recorded !== "string")
1336
1340
  return fail("refused", `the computer ${ref.name}: ${"other" in recorded ? recorded.other : JSON.stringify(recorded)}`);
1337
- if (policy !== undefined && policy !== recorded)
1338
- return fail("refused", `${FIXED}: ${ref.name} was created with network ${recorded}, not ${policy}`);
1339
- let read = recorded;
1340
- if (recorded === "none") {
1341
- const root = rootRecorded(found.value.tags, ref.name);
1342
- if (root)
1343
- return root;
1344
- const inside = await this.#inside(found.value.sandbox, ref.name, signal);
1345
- if (!inside.ok)
1346
- return inside;
1347
- const { reached } = inside.value.probe;
1348
- if (reached.length > 0)
1349
- read = { other: `created with network none, yet from inside an answer came back from ${reached.join(", ")}` };
1350
- }
1341
+ const root = rootRecorded(found.value.tags, ref.name);
1342
+ if (root)
1343
+ return root;
1344
+ const inside = await this.#inside(found.value.sandbox, ref.name, signal);
1345
+ if (!inside.ok)
1346
+ return inside;
1347
+ const { reached } = inside.value.probe;
1348
+ const read = reached.length > 0 ? { other: `created with network none, yet from inside an answer came back from ${reached.join(", ")}` } : recorded;
1351
1349
  if (policy === undefined || policy === read)
1352
1350
  return ok(read);
1353
1351
  return fail("refused", `${ref.name} was asked to keep network ${policy}, and reads back: ${typeof read === "string" ? read : JSON.stringify(read)}`);
@@ -58,6 +58,25 @@ export declare const ARCHIL_REGION = "[a-z0-9]+-[a-z0-9][a-z0-9-]{0,62}";
58
58
  export declare function archilRefusals(spec: ComputerSpec): Refusal[];
59
59
  /** The sha256 of the helper this package ships (box/agentrun-archil): the one an image must have. */
60
60
  export declare function helperSha256(): string;
61
+ /**
62
+ * An egress gateway for the archil client (parcha-proxy's archil-egress): with one, the helper's mount starts
63
+ * `computerd archil-relay` and redirects root's TCP to Archil's 8100 and 32050 to it, and the relay carries each
64
+ * connection to the gateway's lane for its port with a PROXY v2 header naming the original destination. The gateway
65
+ * forwards only to a destination that proves, by certificate, the Archil name the client asked for.
66
+ */
67
+ export interface ArchilEgress {
68
+ /** The gateway's IPv4 address. */
69
+ gateway: string;
70
+ /** The gateway's port for the client's connections to 8100 (the mount endpoint). */
71
+ mountLane: number;
72
+ /** The gateway's port for the client's connections to 32050 (the file servers). */
73
+ dataLane: number;
74
+ }
75
+ /**
76
+ * Reads `<IPv4 gateway>:<mount lane>:<data lane>`, such as 10.60.0.40:18100:42050, as the helper checks it: an IPv4
77
+ * address and two different ports, neither 8100 nor 32050. Anything else throws, in words.
78
+ */
79
+ export declare function archilEgressOf(text: string): ArchilEgress;
61
80
  export interface ArchilMountOptions {
62
81
  root: ArchilRoot;
63
82
  mount: ArchilMount;
@@ -71,6 +90,8 @@ export interface ArchilMountOptions {
71
90
  }>>;
72
91
  /** The bound of each step in the computer. */
73
92
  timeoutMs: number;
93
+ /** The egress gateway the archil client reaches Archil through; none, and it reaches Archil as the computer's network allows. */
94
+ egress?: ArchilEgress;
74
95
  signal?: AbortSignal;
75
96
  }
76
97
  /**
@@ -85,10 +106,11 @@ export interface ArchilMountOptions {
85
106
  * Another computer of the run at the claim's own epoch is never forced off: while one is listed there is no
86
107
  * revoke, and a held folder refuses in words;
87
108
  * 4. serve: the resident sync server, which holds no token.
88
- * The archil client and serve run in the computer's own network namespace, which reaches Archil; the tools' network is
89
- * init's own namespace, loopback alone (computerd init --own-network), so there is no firewall to set here.
109
+ * The archil client and serve run in the computer's own network namespace, which reaches Archil (through the egress
110
+ * gateway, when one is given: the helper sets the relay and its redirect); the tools' network is init's own namespace,
111
+ * loopback alone (computerd init --own-network), so there is no firewall to set here.
90
112
  */
91
- export declare function archilMount({ root, mount, self: computer, releaseOlder, timeoutMs, signal }: ArchilMountOptions): Promise<Result<void>>;
113
+ export declare function archilMount({ root, mount, self: computer, releaseOlder, timeoutMs, egress, signal }: ArchilMountOptions): Promise<Result<void>>;
92
114
  /**
93
115
  * A computerd client whose every call that may change the folder (files.write, move, remove and mkdir; tar.push.begin,
94
116
  * which makes the destination and the folders above it, so a push never ended leaves none unsynced; tar.push.end, and
@@ -11,7 +11,7 @@ import { createHash } from "node:crypto";
11
11
  import { readFileSync } from "node:fs";
12
12
  import { EPOCH_LABEL, epochOf, RUN_LABEL, runProblem } from "./labels.js";
13
13
  import { readBackOf, WORKSPACE } from "./mount.js";
14
- import { fail, ok } from "./result.js";
14
+ import { fail, failAs, ok } from "./result.js";
15
15
  /** Where the image has the root helper, root:root 0755. */
16
16
  export const ARCHIL_HELPER = "/usr/local/sbin/agentrun-archil";
17
17
  /** The user computerd runs every tool as in a computer with an Archil mount: no sudo, no capability, no token. */
@@ -120,7 +120,12 @@ const PREFLIGHT = [
120
120
  'echo "archil $(/usr/bin/archil --version 2>/dev/null | head -n 1)"',
121
121
  `echo "tool $(id -u ${ARCHIL_TOOL_USER} 2>/dev/null):$(id -g ${ARCHIL_TOOL_USER} 2>/dev/null)"`,
122
122
  'echo "sudo $(command -v sudo 2>/dev/null || echo none)"',
123
+ // The FUSE device, which the archil client mounts through: the runtime gives it, not the image (Daytona's GPU host
124
+ // gives none, live 11-11).
125
+ 'echo "fuse $([ -c /dev/fuse ] && echo present || echo absent)"',
123
126
  ].join("\n");
127
+ /** Why a computer's preflight says the Archil folder cannot be mounted at all, before anything else is checked. */
128
+ const NO_FUSE = "this computer has no /dev/fuse, so the Archil folder can't be mounted";
124
129
  /** How the preflight's words differ from the image the package ships, one line each; none when they do not. */
125
130
  function preflightDrift(output, expectedSha) {
126
131
  const lines = new Map();
@@ -144,14 +149,36 @@ function preflightDrift(output, expectedSha) {
144
149
  found.push(`the tool user ${ARCHIL_TOOL_USER} is not ${ARCHIL_TOOL_UID}:${ARCHIL_TOOL_UID} (${show(lines.get("tool"))})`);
145
150
  if (lines.get("sudo") !== "none")
146
151
  found.push(`the image has sudo (${show(lines.get("sudo"))}), which gives the tool user a way to root`);
152
+ if (lines.get("fuse") !== "present")
153
+ found.push(`the preflight did not find /dev/fuse (${show(lines.get("fuse"))})`);
147
154
  return found;
148
155
  }
149
156
  /** What Archil answers a mount of a folder another client holds. */
150
157
  const HELD = "has an outstanding delegation";
158
+ const IPV4 = /^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/;
159
+ const LANE = /^[1-9]\d{0,4}$/;
160
+ /** Archil's own ports, which the computer redirects to the relay: no lane may be one. */
161
+ const ARCHIL_PORTS = new Set([8100, 32050]);
162
+ /**
163
+ * Reads `<IPv4 gateway>:<mount lane>:<data lane>`, such as 10.60.0.40:18100:42050, as the helper checks it: an IPv4
164
+ * address and two different ports, neither 8100 nor 32050. Anything else throws, in words.
165
+ */
166
+ export function archilEgressOf(text) {
167
+ const [gateway = "", mount = "", data = "", ...rest] = text.split(":");
168
+ const mountLane = Number(mount);
169
+ const dataLane = Number(data);
170
+ const lane = (port, n) => LANE.test(port) && n <= 65535 && !ARCHIL_PORTS.has(n);
171
+ if (rest.length > 0 || !IPV4.test(gateway) || !lane(mount, mountLane) || !lane(data, dataLane) || mountLane === dataLane) {
172
+ throw new Error(`the Archil egress is <IPv4 gateway>:<mount lane>:<data lane>, such as 10.60.0.40:18100:42050, with two different ports, neither 8100 nor 32050; not ${JSON.stringify(text)}`);
173
+ }
174
+ return { gateway, mountLane, dataLane };
175
+ }
151
176
  /** The helper's argv for a verb. */
152
- function helper(verb, mount) {
153
- if (verb === "mount" || verb === "revoke")
154
- return [ARCHIL_HELPER, verb, mount.disk, mount.region, mount.folder];
177
+ function helper(verb, mount, egress) {
178
+ if (verb === "mount" || verb === "revoke") {
179
+ const way = egress === undefined ? [] : [`egress=${egress.gateway}:${egress.mountLane}:${egress.dataLane}`];
180
+ return [ARCHIL_HELPER, verb, mount.disk, mount.region, mount.folder, ...way];
181
+ }
155
182
  return [ARCHIL_HELPER, verb];
156
183
  }
157
184
  /**
@@ -166,27 +193,31 @@ function helper(verb, mount) {
166
193
  * Another computer of the run at the claim's own epoch is never forced off: while one is listed there is no
167
194
  * revoke, and a held folder refuses in words;
168
195
  * 4. serve: the resident sync server, which holds no token.
169
- * The archil client and serve run in the computer's own network namespace, which reaches Archil; the tools' network is
170
- * init's own namespace, loopback alone (computerd init --own-network), so there is no firewall to set here.
196
+ * The archil client and serve run in the computer's own network namespace, which reaches Archil (through the egress
197
+ * gateway, when one is given: the helper sets the relay and its redirect); the tools' network is init's own namespace,
198
+ * loopback alone (computerd init --own-network), so there is no firewall to set here.
171
199
  */
172
- export async function archilMount({ root, mount, self: computer, releaseOlder, timeoutMs, signal }) {
200
+ export async function archilMount({ root, mount, self: computer, releaseOlder, timeoutMs, egress, signal }) {
173
201
  const step = async (argv, what, stdin) => {
174
202
  const ran = await root.run(argv, { timeoutMs, ...(stdin === undefined ? {} : { stdin }), ...(signal ? { signal } : {}) });
175
203
  if (!ran.ok)
176
- return fail(ran.error.code, `archil ${what} in the computer could not run: ${scrub(ran.error.message, mount.token)}`);
204
+ return failAs(ran.error, `archil ${what} in the computer could not run: ${scrub(ran.error.message, mount.token)}`);
177
205
  return ran;
178
206
  };
179
207
  const failed = (what, ran, code = "refused") => fail(code, `archil ${what} in the computer failed (exit ${ran.exitCode}): ${scrub(ran.output, mount.token)}`);
180
208
  const pre = await step(["sh", "-c", PREFLIGHT, "sh", ARCHIL_HELPER], "preflight");
181
209
  if (!pre.ok)
182
210
  return pre;
211
+ // No FUSE device: the mount cannot happen whatever else holds, so that is the one reason given.
212
+ if (/^fuse absent$/m.test(pre.value.output))
213
+ return fail("refused", NO_FUSE);
183
214
  const drift = preflightDrift(pre.value.output, helperSha256());
184
215
  if (pre.value.exitCode !== 0 || drift.length > 0) {
185
216
  return fail("refused", `the computer is not as the Archil image makes it: ${drift.length > 0 ? drift.join("; ") : `the preflight exited ${pre.value.exitCode}`}`);
186
217
  }
187
218
  const older = await releaseOlder();
188
219
  if (!older.ok)
189
- return fail(older.error.code, `the takeover could not release the run's lower epochs, so nothing was revoked or mounted: ${older.error.message}`);
220
+ return failAs(older.error, `the takeover could not release the run's lower epochs, so nothing was revoked or mounted: ${older.error.message}`);
190
221
  const twinsOf = (kept) => kept.filter((ref) => ref.id !== computer.id).map((ref) => ref.name);
191
222
  const twins = twinsOf(older.value.kept);
192
223
  // Right before any force, the run's listing is read again: a higher epoch made since (two creates of one run
@@ -194,7 +225,7 @@ export async function archilMount({ root, mount, self: computer, releaseOlder, t
194
225
  const beforeForce = async () => {
195
226
  const again = await releaseOlder();
196
227
  if (!again.ok)
197
- return fail(again.error.code, `the run's computers, listed again right before the force, stop it, so nothing was revoked: ${again.error.message}`);
228
+ return failAs(again.error, `the run's computers, listed again right before the force, stop it, so nothing was revoked: ${again.error.message}`);
198
229
  const late = twinsOf(again.value.kept);
199
230
  if (late.length > 0)
200
231
  return fail("refused", `the run has ${late.join(", ")} at this claim's same epoch, listed right before the force: a create never forces off a computer of its own epoch, so nothing was revoked`);
@@ -207,7 +238,7 @@ export async function archilMount({ root, mount, self: computer, releaseOlder, t
207
238
  return checked;
208
239
  }
209
240
  let verb = force ? "revoke" : "mount";
210
- let took = await step(helper(verb, mount), verb, `${mount.token}\n`);
241
+ let took = await step(helper(verb, mount, egress), verb, `${mount.token}\n`);
211
242
  if (!took.ok)
212
243
  return took;
213
244
  if (verb === "mount" && took.value.exitCode !== 0 && took.value.output.includes(HELD) && twins.length > 0) {
@@ -218,7 +249,7 @@ export async function archilMount({ root, mount, self: computer, releaseOlder, t
218
249
  if (!checked.ok)
219
250
  return checked;
220
251
  verb = "revoke";
221
- took = await step(helper(verb, mount), verb, `${mount.token}\n`);
252
+ took = await step(helper(verb, mount, egress), verb, `${mount.token}\n`);
222
253
  if (!took.ok)
223
254
  return took;
224
255
  }