@parcha/agentrun-computer 0.1.0-beta.37 → 0.1.0-beta.39

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 (124) hide show
  1. package/README.md +341 -260
  2. package/box/Dockerfile +18 -1
  3. package/box/README.md +14 -0
  4. package/box/build-daytona.py +2 -2
  5. package/box/build-e2b.mjs +41 -18
  6. package/box/recipe.d.mts +5 -0
  7. package/box/recipe.mjs +43 -0
  8. package/dist/agent37.d.ts +18 -66
  9. package/dist/agent37.js +187 -464
  10. package/dist/box-image.d.ts +14 -0
  11. package/dist/box-image.js +24 -0
  12. package/dist/browserbase.d.ts +0 -6
  13. package/dist/browserbase.js +1 -5
  14. package/dist/client.d.ts +12 -3
  15. package/dist/client.js +39 -4
  16. package/dist/computerd-linux-amd64 +0 -0
  17. package/dist/computerd-linux-arm64 +0 -0
  18. package/dist/computerd.json +4 -0
  19. package/dist/conformance/agent37.d.ts +9 -4
  20. package/dist/conformance/agent37.js +23 -11
  21. package/dist/conformance/browserbase.js +3 -3
  22. package/dist/conformance/cases/apps.d.ts +6 -0
  23. package/dist/conformance/cases/apps.js +18 -5
  24. package/dist/conformance/cases/isolation.d.ts +22 -5
  25. package/dist/conformance/cases/isolation.js +97 -16
  26. package/dist/conformance/cases/mount.js +5 -3
  27. package/dist/conformance/cases/provider.js +41 -0
  28. package/dist/conformance/cli.js +72 -11
  29. package/dist/conformance/daytona.d.ts +9 -20
  30. package/dist/conformance/daytona.js +12 -21
  31. package/dist/conformance/e2b.js +9 -4
  32. package/dist/conformance/exec-stream.d.ts +52 -0
  33. package/dist/conformance/exec-stream.js +493 -0
  34. package/dist/conformance/kernel.js +2 -2
  35. package/dist/conformance/modal.js +1 -1
  36. package/dist/conformance/orgo.js +2 -2
  37. package/dist/conformance/sweep.js +8 -8
  38. package/dist/conformance/types.d.ts +2 -2
  39. package/dist/create-requests.d.ts +1 -1
  40. package/dist/daytona.d.ts +17 -133
  41. package/dist/daytona.js +396 -1452
  42. package/dist/descriptor.d.ts +11 -4
  43. package/dist/descriptor.js +7 -0
  44. package/dist/descriptors/agent37.d.ts +3 -11
  45. package/dist/descriptors/agent37.js +9 -10
  46. package/dist/descriptors/daytona.d.ts +7 -6
  47. package/dist/descriptors/daytona.js +14 -7
  48. package/dist/descriptors/docker.d.ts +13 -1
  49. package/dist/descriptors/docker.js +3 -1
  50. package/dist/descriptors/e2b.d.ts +2 -9
  51. package/dist/descriptors/e2b.js +8 -8
  52. package/dist/descriptors/index.d.ts +25 -24
  53. package/dist/descriptors/index.js +1 -3
  54. package/dist/descriptors/modal.d.ts +2 -6
  55. package/dist/descriptors/modal.js +8 -6
  56. package/dist/descriptors/orgo.js +2 -1
  57. package/dist/descriptors/shared.d.ts +1 -1
  58. package/dist/descriptors/shared.js +2 -2
  59. package/dist/desktop.d.ts +18 -4
  60. package/dist/desktop.js +89 -9
  61. package/dist/docker/egress-main.js +23 -15
  62. package/dist/docker/egress.d.ts +6 -4
  63. package/dist/docker/egress.js +24 -16
  64. package/dist/docker/inspect.d.ts +2 -2
  65. package/dist/docker/inspect.js +5 -5
  66. package/dist/docker.d.ts +6 -11
  67. package/dist/docker.js +13 -16
  68. package/dist/drift.js +4 -4
  69. package/dist/e2b.d.ts +22 -130
  70. package/dist/e2b.js +163 -243
  71. package/dist/host.d.ts +136 -104
  72. package/dist/host.js +8 -1
  73. package/dist/hosted/network.d.ts +23 -0
  74. package/dist/hosted/network.js +77 -0
  75. package/dist/hosted/process.d.ts +24 -8
  76. package/dist/hosted/process.js +80 -44
  77. package/dist/hosted/provider.d.ts +38 -22
  78. package/dist/hosted/provider.js +500 -341
  79. package/dist/hosted/rest.d.ts +74 -0
  80. package/dist/hosted/rest.js +126 -0
  81. package/dist/hosted/scripts.d.ts +21 -3
  82. package/dist/hosted/scripts.js +76 -14
  83. package/dist/hosted/ssh-exec.d.ts +99 -0
  84. package/dist/hosted/ssh-exec.js +464 -0
  85. package/dist/hosted/values.d.ts +26 -0
  86. package/dist/hosted/values.js +63 -0
  87. package/dist/index.d.ts +2 -2
  88. package/dist/index.js +2 -2
  89. package/dist/isolation.d.ts +0 -2
  90. package/dist/isolation.js +3 -4
  91. package/dist/kernel.d.ts +0 -6
  92. package/dist/kernel.js +1 -5
  93. package/dist/kinds.d.ts +3 -1
  94. package/dist/local-chrome.d.ts +0 -6
  95. package/dist/local-chrome.js +1 -5
  96. package/dist/modal.d.ts +15 -86
  97. package/dist/modal.js +67 -185
  98. package/dist/mount-archil.d.ts +13 -8
  99. package/dist/mount-archil.js +27 -17
  100. package/dist/mount.d.ts +10 -4
  101. package/dist/mount.js +8 -4
  102. package/dist/orgo.d.ts +0 -9
  103. package/dist/orgo.js +8 -13
  104. package/dist/phone-harness.d.ts +0 -6
  105. package/dist/phone-harness.js +0 -4
  106. package/dist/protocol.d.ts +4 -1
  107. package/dist/protocol.js +1 -0
  108. package/dist/provider.d.ts +2 -2
  109. package/dist/providers.d.ts +15 -13
  110. package/dist/screen-watch.js +34 -6
  111. package/dist/surface/api.d.ts +14 -11
  112. package/dist/surface/core.d.ts +23 -5
  113. package/dist/surface/core.js +105 -15
  114. package/dist/surface/index.d.ts +1 -1
  115. package/dist/surface/index.js +1 -1
  116. package/dist/surface/outline.d.ts +2 -0
  117. package/dist/surface/outline.js +2 -1
  118. package/dist/surface/script.d.ts +4 -0
  119. package/dist/surface/script.js +11 -3
  120. package/dist/ui-engine.js +19 -3
  121. package/package.json +2 -3
  122. package/box/build-agent37.mjs +0 -177
  123. package/dist/conformance/daytona-sweep.d.ts +0 -18
  124. package/dist/conformance/daytona-sweep.js +0 -126
package/dist/kernel.js CHANGED
@@ -37,10 +37,6 @@ export const KERNEL_MIN_LIFETIME_MS = 10_000;
37
37
  export const KERNEL_MAX_LIFETIME_MS = 259_200_000;
38
38
  /** The most pages a list reads before it fails rather than run on. */
39
39
  const MAX_PAGES = 100;
40
- /** A browser takes no mount. */
41
- export const MOUNT = KERNEL.mounts;
42
- /** The one configuration it offers, its descriptor's: a browser with a CDP target and a live view. */
43
- export const CAPABILITIES = KERNEL.capabilities;
44
40
  /** Kernel's REST API over fetch: the default request. */
45
41
  export function kernelRest({ apiKey, apiUrl = KERNEL_API_URL, fetch: fetcher = fetch }) {
46
42
  const o = { vendor: NAME, fetch: fetcher, base: httpsBase(apiUrl, "the Kernel API URL"), headers: { Authorization: `Bearer ${apiKey}` } };
@@ -87,7 +83,7 @@ export class KernelProvider {
87
83
  isolation: "vm",
88
84
  os: "linux",
89
85
  daemon: "none",
90
- groups: [...CAPABILITIES[0].groups],
86
+ groups: [...KERNEL.capabilities[0].groups],
91
87
  maxLifetimeMs: KERNEL_MAX_LIFETIME_MS,
92
88
  release: ["delete"],
93
89
  browser: KERNEL_BROWSER(),
package/dist/kinds.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { DescriptorKey, DescriptorSetting, HostCommand, ParkedConfiguration, ProviderDescriptor } from "./descriptor.js";
2
- import type { MountKind } from "./mount.js";
2
+ import type { MountKind, Unmounted } from "./mount.js";
3
3
  import type { ComputerKind, Group, HelloResult } from "./protocol.js";
4
4
  import type { ComputerCapabilities, NetworkForm } from "./provider.js";
5
5
  import type { Result } from "./result.js";
@@ -66,6 +66,8 @@ export interface ProviderEntry {
66
66
  readonly settings?: readonly DescriptorSetting[];
67
67
  /** The mount kinds its computers take; [] cannot mount the run's folder. */
68
68
  readonly mounts: readonly MountKind[];
69
+ /** Why its computers take none of these mount kinds, each in one sentence (descriptor.ts). */
70
+ readonly unmounted?: Unmounted;
69
71
  /**
70
72
  * The network forms its computers make, its descriptor's: ["none"], a remote computer whose programs run in a network
71
73
  * of their own; ["open"], the vendor's own network, which no allowlist of this server reaches; Docker's all three.
@@ -1,19 +1,13 @@
1
- import type { KindCapabilities } from "./kinds.js";
2
- import type { MountKind } from "./mount.js";
3
1
  import type { AttachedComputer, CallContext, ComputerCapabilities, ComputerConnection, ComputerInfo, ComputerProvider, ComputerRef, ComputerSpec, CreateContext, CreatedComputer, NetworkPolicy, NetworkSpec, Refusal } from "./provider.js";
4
2
  import { type Result } from "./result.js";
5
3
  /** The longest a local browser lives: a day, as pi-browser's local Chrome. */
6
4
  export declare const LOCAL_MAX_LIFETIME_MS: number;
7
- /** A browser takes no mount: its descriptor's (descriptors/local-chrome.ts). */
8
- export declare const MOUNT: readonly MountKind[];
9
5
  /** A spec's network as this browser's proxy takes it: open (no list), a list (parseAllow's), or why it can't. */
10
6
  export declare function browserNetworkOf(network: unknown): {
11
7
  allow?: string[];
12
8
  } | {
13
9
  problem: string;
14
10
  };
15
- /** The one configuration it offers, its descriptor's: a browser with a CDP target. */
16
- export declare const CAPABILITIES: readonly KindCapabilities[];
17
11
  export interface LocalBrowserOptions {
18
12
  /** The Chrome or Chromium to run; default the one findChrome finds in `env`, then in the usual places. */
19
13
  executablePath?: string;
@@ -45,8 +45,6 @@ const WINDOW = "--window-size=1280,800";
45
45
  const SOCKET_PATH_MAX = 107;
46
46
  /** How long a release waits for the supervisor, then for Chrome, to end. */
47
47
  const END_MS = 10_000;
48
- /** A browser takes no mount: its descriptor's (descriptors/local-chrome.ts). */
49
- export const MOUNT = LOCAL.mounts;
50
48
  /** The networks a local browser runs on, its descriptor's: through its egress proxy, public addresses ("open"), or only
51
49
  * the hosts of a list ("allow"), public ones still. */
52
50
  const NETWORK = LOCAL.network;
@@ -75,8 +73,6 @@ const networkRecord = (network) => {
75
73
  };
76
74
  /** A browser's network as list, attach and network() read it back from browser.json. */
77
75
  const networkRead = (record) => (record.allow ? { allow: [...record.allow] } : "open");
78
- /** The one configuration it offers, its descriptor's: a browser with a CDP target. */
79
- export const CAPABILITIES = LOCAL.capabilities;
80
76
  const ID = /^lb-[0-9a-f]{16}$/;
81
77
  const idProblem = (id) => (typeof id === "string" && ID.test(id) ? undefined : `${typeof id === "string" ? JSON.stringify(id) : String(id)} is not a local browser's id`);
82
78
  const refOf = (id) => ({ id, name: id });
@@ -124,7 +120,7 @@ export class LocalBrowserProvider {
124
120
  isolation: "host",
125
121
  os: "linux",
126
122
  daemon: "none",
127
- groups: [...CAPABILITIES[0].groups],
123
+ groups: [...LOCAL.capabilities[0].groups],
128
124
  maxLifetimeMs: LOCAL_MAX_LIFETIME_MS,
129
125
  release: ["delete"],
130
126
  browser: { timeout: "wall-clock" },
package/dist/modal.d.ts CHANGED
@@ -1,77 +1,13 @@
1
1
  import { HostedProvider, type HostedOptions, type HostedTimeouts } from "./hosted/provider.js";
2
- import type { KindCapabilities } from "./kinds.js";
3
- import type { MountKind } from "./mount.js";
4
- /** The App sandboxes are made in (modal-client@64880502:js/src/app.ts:32-61). */
5
- export interface ModalApp {
6
- readonly appId: string;
7
- }
8
- /** An Image, built on Modal's side when a sandbox is created from it (js/src/image.ts:311-401). */
9
- export interface ModalImage {
10
- dockerfileCommands(commands: string[]): ModalImage;
11
- }
12
- /** What sandboxes.create is given: every field is one of the SDK's SandboxCreateParams (js/src/sandbox.ts:356-474). */
13
- export interface ModalCreateParams {
14
- /** vm, or gvisor for a GPU computer: Modal offers GPUs on gVisor only. */
15
- runtime: ModalRuntime;
16
- /** The GPUs, as the SDK takes them ("T4", "A100-80GB:4"): a GPU computer only. */
17
- gpu?: string;
18
- command: string[];
19
- timeoutMs: number;
20
- workdir: string;
21
- cpu: number;
22
- cpuLimit: number;
23
- memoryMiB: number;
24
- memoryLimitMiB: number;
25
- blockNetwork?: true;
26
- tags: Record<string, string>;
27
- }
28
- /** A program's stdin in binary mode: the SDK's ModalWriteStream (js/src/streams.ts:33-39) and WritableStream's close. */
29
- export interface ModalByteSink {
30
- writeBytes(bytes: Uint8Array): Promise<void>;
31
- close(): Promise<void>;
32
- }
33
- /** One program started by exec in binary mode: the part of the SDK's ContainerProcess read here (sandbox.ts:2774-2914). */
34
- export interface ModalProcess {
35
- readonly stdin: ModalByteSink;
36
- readonly stdout: AsyncIterable<Uint8Array>;
37
- readonly stderr: AsyncIterable<Uint8Array>;
38
- wait(): Promise<number>;
39
- }
40
- /** The part of the SDK's Sandbox called here (sandbox.ts:1624-2772). */
41
- export interface ModalSandbox {
42
- readonly sandboxId: string;
43
- exec(command: string[], params: {
44
- mode: "binary";
45
- }): Promise<ModalProcess>;
46
- /** null while the sandbox runs, its exit code once it has finished. */
47
- poll(): Promise<number | null>;
48
- getTags(): Promise<Record<string, string>>;
49
- terminate(): Promise<void>;
50
- }
51
- /** The part of the SDK's ModalClient this provider calls. The host passes its own client. */
52
- export interface ModalSdk {
53
- readonly apps: {
54
- fromName(name: string, params: {
55
- createIfMissing: boolean;
56
- }): Promise<ModalApp>;
57
- };
58
- /** fromId opens an image Modal already holds (im-..., as box/build-modal.py prints it); a spec naming one needs it. */
59
- readonly images: {
60
- fromRegistry(tag: string): ModalImage;
61
- fromId?(id: string): Promise<ModalImage>;
62
- };
63
- readonly sandboxes: {
64
- create(app: ModalApp, image: ModalImage, params: ModalCreateParams): Promise<ModalSandbox>;
65
- fromId(id: string): Promise<ModalSandbox>;
66
- list(params: {
67
- appId: string;
68
- tags: Record<string, string>;
69
- }): AsyncIterable<ModalSandbox>;
70
- };
71
- }
2
+ import { type Result } from "./result.js";
3
+ /**
4
+ * The SDK's own types, imported as types only: erased at build, so nothing loads the SDK from here. The host passes its
5
+ * own client (or the constructor), which these name.
6
+ */
7
+ export type ModalSdk = object;
72
8
  /** The Modal provider's options: the client and the app, then the shared adapter's (HostedOptions). */
73
- export interface ModalProviderOptions extends Omit<HostedOptions, "label" | "kind" | "desktop" | "maxLifetimeMs"> {
74
- /** The host's Modal client, or anything with the same slice. */
9
+ export interface ModalProviderOptions extends Omit<HostedOptions, "kind" | "desktop" | "maxLifetimeMs"> {
10
+ /** The host's Modal client. */
75
11
  sdk: ModalSdk;
76
12
  /** The Modal App the sandboxes live in; made when missing. */
77
13
  app: string;
@@ -79,12 +15,6 @@ export interface ModalProviderOptions extends Omit<HostedOptions, "label" | "kin
79
15
  maxLifetimeMs?: number;
80
16
  timeouts?: Partial<HostedTimeouts>;
81
17
  }
82
- /** The mount kinds a Modal computer takes, as capabilities().mount declares them: the run's folder on an Archil disk. */
83
- export declare const MOUNT: readonly MountKind[];
84
- /** The runtime a Modal sandbox runs under: vm, or gvisor for a GPU computer (Modal offers GPUs on gVisor only). */
85
- export type ModalRuntime = "vm" | "gvisor";
86
- /** The machine kind, groups and GPUs of its one configuration (its descriptor's): a linux computer, with GPUs when asked. */
87
- export declare const CAPABILITIES: readonly KindCapabilities[];
88
18
  /** The SDK's default server (modal-client@64880502:js/src/config.ts:143). */
89
19
  export declare const MODAL_DEFAULT_SERVER_URL = "https://api.modal.com:443";
90
20
  /** What modalClient gives the SDK's ModalClient: the token, explicitly, so the SDK fills none of it in. */
@@ -132,14 +62,6 @@ export declare function modalClient({ tokenId, tokenSecret, serverUrl, ModalClie
132
62
  export declare function create(options: ModalCreateOptions): Promise<ModalProvider>;
133
63
  /** The conformance CLI's module for Modal: its live switch, the run's 30-minute cap and the drifted twin. */
134
64
  export declare const conformance: () => Promise<typeof import("./conformance/modal.js")>;
135
- /**
136
- * The tags a sandbox carries for a machine's labels. Every label is its own tag, with one exception that keeps an
137
- * Archil computer within Modal's 512 bytes: the mount label's folder, agents/<agent>/runs/<run>/work, names the run its
138
- * agentrun.run label holds, so the tag records the agent alone, and labelsOf puts the folder back.
139
- */
140
- export declare function tagsOf(labels: Record<string, string>): Record<string, string>;
141
- /** A sandbox's labels from its tags: tagsOf undone. */
142
- export declare function labelsOf(tags: Record<string, string>): Record<string, string>;
143
65
  /**
144
66
  * Computers that are Modal sandboxes on the VM runtime, or on gVisor with a GPU, on the shared adapter. The daemon is
145
67
  * streamed in through an exec's stdin right after create, while the sandbox's command, the entrypoint, waits for it and
@@ -148,5 +70,12 @@ export declare function labelsOf(tags: Record<string, string>): Record<string, s
148
70
  * memoryMb) and name the uid its programs run as, never root.
149
71
  */
150
72
  export declare class ModalProvider extends HostedProvider {
73
+ /**
74
+ * The provider contract's prepareImage (its descriptor declares it): the box image the release publishes, by its
75
+ * public registry tag (box-image.ts), which has the Archil client and its root helper. No call: Modal pulls a
76
+ * registry tag at the first create from it in a workspace (images.fromRegistry), so there is nothing to pull ahead of
77
+ * it, and onWait is never told (the claim's wait is the create's). A sandbox with GPUs starts from the same image.
78
+ */
79
+ prepareImage(): Promise<Result<string>>;
151
80
  constructor(options: ModalProviderOptions);
152
81
  }
package/dist/modal.js CHANGED
@@ -1,28 +1,12 @@
1
- // The Modal host: Modal sandboxes on the VM runtime, and on gVisor for a GPU computer (Modal's one GPU runtime), every
2
- // call through the host's own Modal JS SDK client, of which this package names only the slice it uses (ModalSdk) and
3
- // imports nothing. A Modal sandbox's command is its main process, so computerd is pid1: the sandbox's command is the
4
- // shared entrypoint, which waits for the daemon and becomes init, and Modal finishes the sandbox when init exits. Modal
5
- // has no file API, so the daemon goes in through exec's stdin; it has no kill for an exec (closing stdin ends one), and
6
- // reads no network back, so the probe from inside stands for network none. The rest of the computer is the shared
7
- // machine-host adapter's (./hosted/provider.ts). Every SDK fact below is cited in the README's Modal section, from
8
- // modal-client@64880502 (js/src) and Modal's docs.
9
- import { MODAL, MODAL_DEFAULT_IMAGE, MODAL_GPU } from "./descriptors/modal.js";
10
- import { COMPUTER_LABEL, DEADLINE_LABEL, DEFAULT_CPUS, DEFAULT_MEMORY_MB, WORK } from "./drift.js";
11
- import { HostedProvider, IMAGE_LABEL, MAX_LABEL, NAME_LABEL } from "./hosted/provider.js";
12
- import { words } from "./hosted/process.js";
13
- import { RUN_LABEL } from "./labels.js";
14
- import { ARCHIL_MOUNT_LABEL, archilLabels } from "./mount-archil.js";
15
- import { failFor, ok } from "./result.js";
16
- /** This module's failures: one with code vendor names Modal. */
17
- const fail = failFor("modal");
18
- /** The mount kinds a Modal computer takes, as capabilities().mount declares them: the run's folder on an Archil disk. */
19
- export const MOUNT = MODAL.mounts;
20
- /** A copy of its descriptor's MODAL_GPU, so no caller can change the provider's own. */
21
- const modalGpuCapability = () => ({ ...MODAL_GPU, types: [...MODAL_GPU.types], mounts: [] });
1
+ import { boxImageRef } from "./box-image.js";
2
+ import { MODAL } from "./descriptors/modal.js";
3
+ import { DEFAULT_CPUS, DEFAULT_MEMORY_MB, WORK } from "./drift.js";
4
+ import { HostError } from "./host.js";
5
+ import { HostedProvider } from "./hosted/provider.js";
6
+ import { isWhole } from "./hosted/values.js";
7
+ import { ok } from "./result.js";
22
8
  /** A GPU as the SDK takes it: the type, then :count past one ("T4", "H100:8"). */
23
9
  const modalGpu = ({ type, count }) => (count === 1 ? type : `${type}:${count}`);
24
- /** The machine kind, groups and GPUs of its one configuration (its descriptor's): a linux computer, with GPUs when asked. */
25
- export const CAPABILITIES = MODAL.capabilities;
26
10
  /** The SDK's default server (modal-client@64880502:js/src/config.ts:143). */
27
11
  export const MODAL_DEFAULT_SERVER_URL = "https://api.modal.com:443";
28
12
  /** Not a literal, so no type checker or bundler resolves the SDK from this package. */
@@ -108,11 +92,7 @@ const CPUS_PER_CORE = 2;
108
92
  * terminate is asynchronous, and the daemon is streamed in through exec.
109
93
  */
110
94
  const MODAL_TIMEOUTS = { requestMs: 60_000, createMs: 600_000, uploadMs: 300_000, listMs: 120_000, goneMs: 120_000, pollMs: 500, mountMs: 120_000 };
111
- /** An Archil folder agents/<agent>/runs/<run>/work, the shape the shared check holds it to. */
112
- const FOLDER = /^agents\/([^/]+)\/runs\/([^/]+)\/work$/;
113
95
  const isNumber = (value) => typeof value === "number" && Number.isFinite(value);
114
- const isWhole = (value) => typeof value === "number" && Number.isSafeInteger(value);
115
- const isLabels = (value) => typeof value === "object" && value !== null && !Array.isArray(value) && Object.values(value).every((one) => typeof one === "string");
116
96
  /** The SDK names its errors (js/src/errors.ts); a call that failed on the wire carries a gRPC status code. */
117
97
  function codeOf(error) {
118
98
  const { name, code } = (error ?? {});
@@ -129,68 +109,9 @@ function codeOf(error) {
129
109
  return "gone";
130
110
  return "vendor";
131
111
  }
132
- /**
133
- * The tags a sandbox carries for a machine's labels. Every label is its own tag, with one exception that keeps an
134
- * Archil computer within Modal's 512 bytes: the mount label's folder, agents/<agent>/runs/<run>/work, names the run its
135
- * agentrun.run label holds, so the tag records the agent alone, and labelsOf puts the folder back.
136
- */
137
- export function tagsOf(labels) {
138
- const tags = { ...labels };
139
- const text = labels[ARCHIL_MOUNT_LABEL];
140
- if (text === undefined)
141
- return tags;
142
- let mount;
143
- try {
144
- mount = JSON.parse(text);
145
- }
146
- catch {
147
- return tags;
148
- }
149
- const { kind, disk, region, folder } = mount ?? {};
150
- const found = typeof folder === "string" ? FOLDER.exec(folder) : null;
151
- // Only a label exactly as the adapter writes it (archilLabels) is shortened, so labelsOf gives back the same text.
152
- if (found === null || found[2] !== labels[RUN_LABEL] || text !== archilLabels({ kind: "archil", disk, region, folder })[ARCHIL_MOUNT_LABEL])
153
- return tags;
154
- tags[ARCHIL_MOUNT_LABEL] = JSON.stringify({ kind, disk, region, agent: found[1] });
155
- return tags;
156
- }
157
- /** A sandbox's labels from its tags: tagsOf undone. */
158
- export function labelsOf(tags) {
159
- const labels = { ...tags };
160
- const text = tags[ARCHIL_MOUNT_LABEL];
161
- const run = tags[RUN_LABEL];
162
- if (text === undefined || run === undefined)
163
- return labels;
164
- try {
165
- const { kind, disk, region, agent, ...rest } = (JSON.parse(text) ?? {});
166
- if (kind !== "archil" || typeof disk !== "string" || typeof region !== "string" || typeof agent !== "string" || Object.keys(rest).length > 0)
167
- return labels;
168
- Object.assign(labels, archilLabels({ kind: "archil", disk, region, folder: `agents/${agent}/runs/${run}/work` }));
169
- }
170
- catch {
171
- // Not the shortened mount: the tag as it is.
172
- }
173
- return labels;
174
- }
175
- /** The bytes Modal counts of `tags`: every name and value, in UTF-8. */
176
- const tagBytes = (tags) => Object.entries(tags).reduce((sum, [key, value]) => sum + Buffer.byteLength(key) + Buffer.byteLength(value), 0);
177
- /** A sandbox's tags as the adapter would make them of spec: its labels, the adapter's own, its name and deadline as long as create's. */
178
- function tagsForSpec(spec) {
179
- const at = new Date(0).toISOString();
180
- const own = { [COMPUTER_LABEL]: "1", [NAME_LABEL]: "computer-000000000000", [DEADLINE_LABEL]: at, [IMAGE_LABEL]: spec.image, [MAX_LABEL]: at };
181
- return tagsOf({ ...spec.labels, ...own, ...(spec.mount?.kind === "archil" ? archilLabels(spec.mount) : {}) });
182
- }
183
- /** Why tags are past Modal's bound, or undefined. */
184
- function tagProblem(tags) {
185
- const bytes = tagBytes(tags);
186
- if (bytes <= MAX_TAG_BYTES)
187
- return undefined;
188
- const sizes = Object.entries(tags).map(([key, value]) => `${key} ${Buffer.byteLength(key) + Buffer.byteLength(value)}`).join(", ");
189
- return `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`;
190
- }
191
112
  /** Modal's sandboxes as a MachineHost (../host.ts). */
192
113
  class ModalHost {
193
- id = "modal";
114
+ descriptor = MODAL;
194
115
  facts;
195
116
  #sdk;
196
117
  #appName;
@@ -204,7 +125,7 @@ class ModalHost {
204
125
  // The sandbox's command is the entrypoint, which becomes init: Modal finishes the sandbox when that main process
205
126
  // exits (sandbox.ts:384-388), so init's exit ends the computer.
206
127
  daemon: "pid1",
207
- // A GPU computer runs on gVisor, Modal's one GPU runtime (gpu.isolation): vm is every other computer's.
128
+ // A GPU computer runs on gVisor, Modal's one GPU runtime (its descriptor's gpu.isolation): vm is every other computer's.
208
129
  isolation: "vm",
209
130
  lifetime: "vendor",
210
131
  maxLifetimeMs: MAX_LIFETIME_MS,
@@ -212,83 +133,65 @@ class ModalHost {
212
133
  arch: "amd64",
213
134
  // No listener of Modal's own inside a sandbox is documented, so none is declared.
214
135
  vendorAgentPorts: [],
215
- networkReadBack: false,
216
- network: [...MODAL.network],
217
- mounts: [...MOUNT],
218
- release: ["delete"],
219
- gpu: modalGpuCapability(),
220
136
  // Never root: each connection is Modal's exec of the stdio bridge, as Modal's root, outside the daemon.
221
137
  user: ["uid"],
222
- specFields: ["cpus", "memoryMb", "user"],
223
- labelRules: { max: MAX_TAGS },
224
- runtime: (req) => (req.gpu === undefined ? "vm" : "gvisor"),
138
+ labels: { count: MAX_TAGS, bytes: MAX_TAG_BYTES },
225
139
  };
226
140
  }
227
141
  errorCode(error) {
228
142
  return codeOf(error);
229
143
  }
230
- /** The app, looked up (and made when missing) once per provider; a failed lookup is tried again next time. */
231
- async #theApp() {
232
- this.#app ??= await this.#sdk.apps.fromName(this.#appName, { createIfMissing: true });
233
- return this.#app;
234
- }
235
- /** The sandbox with an id: the one create gave, or sandboxes.fromId; undefined when Modal does not know it. */
236
- async #sandbox(id) {
237
- const known = this.#sandboxes.get(id);
238
- if (known !== undefined)
239
- return known;
144
+ /**
145
+ * The app, looked up once per provider, and made when missing by create alone: a listing before any computer makes
146
+ * nothing and finds none (undefined). A failed or missing lookup is tried again next time.
147
+ */
148
+ async #theApp(make) {
240
149
  try {
241
- return await this.#sdk.sandboxes.fromId(id);
150
+ this.#app ??= await this.#sdk.apps.fromName(this.#appName, { createIfMissing: make });
242
151
  }
243
152
  catch (error) {
244
- if (codeOf(error) === "not_found")
245
- return undefined;
246
- throw error;
153
+ if (make || codeOf(error) !== "not_found")
154
+ throw error;
247
155
  }
156
+ return this.#app;
157
+ }
158
+ /** The sandbox with an id: the one create gave, or sandboxes.fromId, which throws NotFoundError for one Modal does not know. */
159
+ async #sandbox(id) {
160
+ return this.#sandboxes.get(id) ?? this.#sdk.sandboxes.fromId(id);
248
161
  }
249
162
  /**
250
163
  * Modal's own rules of a spec, over the adapter's: an image Modal can pull or holds (no option, no space), sizes in
251
- * the units Modal takes, and the sandbox's tags within Modal's 512 bytes. No call.
164
+ * the units Modal takes. No call; the adapter holds the tags to Modal's 10 and 512 bytes (facts.labels).
252
165
  */
253
166
  check(spec) {
254
167
  const refusals = [];
255
168
  const refuse = (field, message) => refusals.push({ field, message });
256
- const { image, cpus, memoryMb, labels, mount } = (typeof spec === "object" && spec !== null ? spec : {});
169
+ const { image, cpus, memoryMb } = spec;
257
170
  if (typeof image === "string" && (image.startsWith("-") || /\s/.test(image))) {
258
- refuse("image", `an image is a registry tag for linux/amd64 that Modal can pull, such as ${MODAL_DEFAULT_IMAGE}, or an image Modal holds by its id (im-...)`);
171
+ refuse("image", "an image is a registry tag for linux/amd64 that Modal can pull, such as debian:bookworm-slim, or an image Modal holds by its id (im-...)");
259
172
  }
260
173
  if (cpus !== undefined && !(isNumber(cpus) && cpus >= CPU_REQUEST * CPUS_PER_CORE)) {
261
174
  refuse("cpus", `cpus must be a number of CPUs of at least ${CPU_REQUEST * CPUS_PER_CORE}: Modal counts physical cores, 2 CPUs each, and requests ${CPU_REQUEST} of one by default`);
262
175
  }
263
176
  if (memoryMb !== undefined && !(isWhole(memoryMb) && memoryMb > 0))
264
177
  refuse("memoryMb", "memoryMb must be a whole number of MiB above 0");
265
- const archil = mount === undefined || (mount?.kind === "archil" && ["disk", "region", "folder"].every((key) => typeof mount[key] === "string"));
266
- if (refusals.length === 0 && typeof image === "string" && (labels === undefined || isLabels(labels)) && archil) {
267
- const problem = tagProblem(tagsForSpec(spec));
268
- if (problem)
269
- refuse(mount === undefined ? "labels" : "mount", problem);
270
- }
271
178
  return refusals;
272
179
  }
273
180
  /**
274
181
  * sandboxes.create in the app: the request's image (an im- id opened by fromId, else a registry tag) with HOME and the
275
182
  * workdir the computer's home, the entrypoint as its command, the lifetime as its timeout in the whole seconds the
276
- * SDK takes, the spec's sizes as limits over Modal's small default request, no network unless the adapter asks open
277
- * (an Archil computer's root, to reach Archil), and the labels as its tags.
183
+ * SDK takes, the spec's sizes as limits over Modal's small default request, no network unless the adapter asks egress
184
+ * (an Archil computer's root, to reach Archil, or the egress proxy of a network open or a list), and the labels as its tags, on gVisor for a GPU computer.
278
185
  */
279
186
  async create(req, ctx) {
280
187
  void ctx;
281
188
  if (req.command === undefined)
282
- return fail("invalid", "a Modal sandbox's command is the entrypoint the adapter gives a pid1 host, and the request has none");
283
- const tags = tagsOf(req.labels);
284
- const problem = tagProblem(tags);
285
- if (problem)
286
- return fail("refused", problem);
189
+ throw new HostError("invalid", "a Modal sandbox's command is the entrypoint the adapter gives a pid1 host, and the request has none");
287
190
  let base;
288
191
  if (MODAL_IMAGE_ID.test(req.image)) {
289
192
  const fromId = this.#sdk.images.fromId;
290
193
  if (typeof fromId !== "function")
291
- return fail("invalid", `the image ${req.image} is a Modal image id, and options.sdk has no images.fromId to open it: pass the SDK's own ModalClient`);
194
+ throw new HostError("invalid", `the image ${req.image} is a Modal image id, and options.sdk has no images.fromId to open it: pass the SDK's own ModalClient`);
292
195
  base = await fromId.call(this.#sdk.images, req.image);
293
196
  }
294
197
  else
@@ -297,22 +200,21 @@ class ModalHost {
297
200
  const memoryMb = req.memoryMb ?? DEFAULT_MEMORY_MB;
298
201
  const cpuLimit = cpus / CPUS_PER_CORE;
299
202
  const params = {
300
- runtime: this.facts.runtime?.(req) ?? "vm",
301
- ...(req.gpu === undefined ? {} : { gpu: modalGpu(req.gpu) }),
203
+ ...(req.gpu === undefined ? { runtime: "vm" } : { runtime: "gvisor", gpu: modalGpu(req.gpu) }),
302
204
  command: [...req.command],
303
- timeoutMs: Math.ceil((req.lifetimeMs ?? 0) / 1000) * 1000,
205
+ timeoutMs: Math.ceil(req.lifetimeMs / 1000) * 1000,
304
206
  workdir: WORK,
305
207
  cpu: Math.min(CPU_REQUEST, cpuLimit),
306
208
  cpuLimit,
307
209
  memoryMiB: Math.min(MEMORY_REQUEST_MIB, memoryMb),
308
210
  memoryLimitMiB: memoryMb,
309
- ...(req.network === "none" ? { blockNetwork: true } : {}),
310
- tags,
211
+ ...(req.egress ? {} : { blockNetwork: true }),
212
+ tags: req.labels,
311
213
  };
312
214
  const image = base.dockerfileCommands([`ENV HOME=${WORK}`, `WORKDIR ${WORK}`]);
313
- const sandbox = await this.#sdk.sandboxes.create(await this.#theApp(), image, params);
215
+ const sandbox = await this.#sdk.sandboxes.create((await this.#theApp(true)), image, params);
314
216
  this.#sandboxes.set(sandbox.sandboxId, sandbox);
315
- return ok({ id: sandbox.sandboxId });
217
+ return { id: sandbox.sandboxId };
316
218
  }
317
219
  /**
318
220
  * The sandbox as a machine: running while poll reads null (sandbox.ts:2761-2771), its labels from its tags. One that
@@ -321,17 +223,14 @@ class ModalHost {
321
223
  */
322
224
  async get(id, ctx) {
323
225
  void ctx;
324
- const sandbox = await this.#sandbox(id);
325
- if (sandbox === undefined)
326
- return ok(undefined);
327
- return ok(await this.#machine(sandbox));
226
+ return this.#machine(await this.#sandbox(id));
328
227
  }
329
228
  /** One sandbox read: none once it has finished or Modal no longer knows it. */
330
229
  async #machine(sandbox) {
331
230
  try {
332
231
  if ((await sandbox.poll()) !== null)
333
232
  return undefined;
334
- return { id: sandbox.sandboxId, labels: labelsOf(await sandbox.getTags()), state: "running" };
233
+ return { id: sandbox.sandboxId, labels: await sandbox.getTags(), state: "running" };
335
234
  }
336
235
  catch (error) {
337
236
  if (codeOf(error) === "not_found")
@@ -342,92 +241,68 @@ class ModalHost {
342
241
  /**
343
242
  * Every running sandbox in the app whose tags carry these labels: Modal's list asks for running sandboxes only
344
243
  * (includeFinished: false, sandbox.ts:1135-1140), yet one terminated a moment ago is still listed, so each is polled,
345
- * and one finished or no longer known is left out. One bound, ctx.timeoutMs, for the listing and every read.
244
+ * and one finished or no longer known is left out. One bound, ctx.timeoutMs, for the listing and every read. An app
245
+ * not made yet holds none.
346
246
  */
347
247
  async list(labels, ctx) {
348
248
  const until = Date.now() + ctx.timeoutMs;
349
- const app = await this.#theApp();
350
- // The mount label is a tag of another text (tagsOf): the listing filters by the rest, and each read by all.
351
- const { [ARCHIL_MOUNT_LABEL]: _mount, ...filter } = labels;
352
- const iterator = this.#sdk.sandboxes.list({ appId: app.appId, tags: filter })[Symbol.asyncIterator]();
249
+ const app = await this.#theApp(false);
250
+ if (app === undefined)
251
+ return [];
252
+ const iterator = this.#sdk.sandboxes.list({ appId: app.appId, tags: labels })[Symbol.asyncIterator]();
353
253
  const machines = [];
354
254
  try {
355
255
  for (;;) {
356
256
  if (Date.now() >= until)
357
- return fail("timeout", `sandboxes.list read ${machines.length} sandboxes, and did not finish within ${ctx.timeoutMs / 1000} s`);
257
+ throw new HostError("timeout", `sandboxes.list read ${machines.length} sandboxes, and did not finish within ${ctx.timeoutMs / 1000} s`);
358
258
  const next = await iterator.next();
359
259
  if (next.done)
360
260
  break;
361
261
  const machine = await this.#machine(next.value);
362
- if (machine !== undefined && Object.entries(labels).every(([key, value]) => machine.labels[key] === value))
262
+ if (machine !== undefined)
363
263
  machines.push(machine);
364
264
  }
365
265
  }
366
266
  finally {
367
267
  Promise.resolve(iterator.return?.()).catch(() => { });
368
268
  }
369
- return ok(machines);
269
+ return machines;
370
270
  }
371
271
  /**
372
272
  * terminate, which returns before Modal has ended the sandbox (sandbox.ts:1292-1296): the adapter waits for it to be
373
- * gone. One Modal no longer knows, or one that had finished when terminate failed, is done.
273
+ * gone. One Modal no longer knows (not_found, done to the adapter), or one that had finished when terminate failed, is done.
374
274
  */
375
275
  async delete(id, ctx) {
376
276
  void ctx;
377
- const sandbox = await this.#sandbox(id);
378
- this.#sandboxes.delete(id);
379
- if (sandbox === undefined)
380
- return ok(undefined);
277
+ const sandbox = await this.#sandbox(id).finally(() => this.#sandboxes.delete(id));
381
278
  try {
382
279
  await sandbox.terminate();
383
280
  }
384
281
  catch (error) {
385
282
  if (codeOf(error) === "not_found")
386
- return ok(undefined);
283
+ throw error;
387
284
  const finished = await sandbox.poll().then((code) => code !== null, (polled) => codeOf(polled) === "not_found");
388
285
  if (!finished)
389
286
  throw error;
390
287
  }
391
- return ok(undefined);
392
288
  }
393
289
  /**
394
- * exec in binary mode, as root (Modal containers always run as root), outside computerd. Without stdin, it is closed
395
- * at once. Modal has no kill for an exec: kill closes its stdin, which ends the stdio bridge and anything else that
396
- * reads it.
290
+ * exec in binary mode, as root (Modal containers always run as root), outside computerd. Modal has no kill for an
291
+ * exec: kill closes its stdin, which ends the stdio bridge and anything else that reads it.
397
292
  */
398
- async exec(id, argv, { stdin }, ctx) {
293
+ async exec(id, argv, ctx) {
399
294
  void ctx;
400
295
  const sandbox = await this.#sandbox(id);
401
- if (sandbox === undefined)
402
- return fail("not_found", `no Modal sandbox has the id ${id}`);
403
296
  const program = await sandbox.exec([...argv], { mode: "binary" });
404
297
  const close = () => program.stdin.close().catch(() => { });
405
- if (!stdin)
406
- await close();
407
- return ok({
298
+ return {
408
299
  stdout: program.stdout,
409
300
  stderr: program.stderr,
410
301
  write: (bytes) => program.stdin.writeBytes(bytes),
411
302
  end: () => program.stdin.close(),
412
303
  wait: () => program.wait(),
413
304
  kill: async () => void (await close()),
414
- });
415
- }
416
- /**
417
- * Settings' test: the app read without making it (createIfMissing false), which makes nothing, where a listing would
418
- * make the app. An app not made yet is a connection all the same: the token was taken, and the first computer makes it.
419
- */
420
- async testConnection(ctx) {
421
- void ctx;
422
- try {
423
- await this.#sdk.apps.fromName(this.#appName, { createIfMissing: false });
424
- return ok({ detail: `Modal answered: the app ${this.#appName} is there` });
425
- }
426
- catch (error) {
427
- if (codeOf(error) === "not_found")
428
- return ok({ detail: `Modal answered: no app ${this.#appName} yet; the first computer makes it` });
429
- return fail(codeOf(error), `apps.fromName ${this.#appName} failed: ${words(error)}`);
430
- }
305
+ };
431
306
  }
432
307
  }
433
308
  /**
@@ -438,8 +313,18 @@ class ModalHost {
438
313
  * memoryMb) and name the uid its programs run as, never root.
439
314
  */
440
315
  export class ModalProvider extends HostedProvider {
316
+ /**
317
+ * The provider contract's prepareImage (its descriptor declares it): the box image the release publishes, by its
318
+ * public registry tag (box-image.ts), which has the Archil client and its root helper. No call: Modal pulls a
319
+ * registry tag at the first create from it in a workspace (images.fromRegistry), so there is nothing to pull ahead of
320
+ * it, and onWait is never told (the claim's wait is the create's). A sandbox with GPUs starts from the same image.
321
+ */
322
+ async prepareImage() {
323
+ return ok(boxImageRef());
324
+ }
441
325
  constructor(options) {
442
- const { sdk, app, maxLifetimeMs = MAX_LIFETIME_MS, timeouts = {}, ...rest } = options ?? {};
326
+ const { app, timeouts = {}, ...rest } = options ?? {};
327
+ const sdk = options?.sdk;
443
328
  const lacks = [
444
329
  ["apps.fromName", sdk?.apps?.fromName],
445
330
  ["images.fromRegistry", sdk?.images?.fromRegistry],
@@ -451,9 +336,6 @@ export class ModalProvider extends HostedProvider {
451
336
  throw new Error(`options.sdk must be a Modal client; it lacks ${lacks.map(([name]) => name).join(", ")}`);
452
337
  if (typeof app !== "string" || app.trim() === "")
453
338
  throw new Error("options.app, the Modal app's name, is required");
454
- if (!isWhole(maxLifetimeMs) || maxLifetimeMs <= 0 || maxLifetimeMs > MAX_LIFETIME_MS) {
455
- throw new Error(`maxLifetimeMs must be a whole number of ms above 0 and at most 24 hours (${MAX_LIFETIME_MS} ms), Modal's longest timeout`);
456
- }
457
- super(new ModalHost(sdk, app), { ...rest, label: "Modal", kind: "linux", maxLifetimeMs, timeouts: { ...MODAL_TIMEOUTS, ...timeouts } });
339
+ super(new ModalHost(sdk, app), { ...rest, kind: "linux", timeouts: { ...MODAL_TIMEOUTS, ...timeouts } });
458
340
  }
459
341
  }