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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/NOTICE +2 -0
  2. package/README.md +254 -14
  3. package/box/README.md +2 -2
  4. package/box/build-e2b.mjs +1 -1
  5. package/dist/box-image.d.ts +1 -3
  6. package/dist/box-image.js +1 -11
  7. package/dist/boxd.d.ts +126 -0
  8. package/dist/boxd.js +418 -0
  9. package/dist/cloudflare.d.ts +32 -0
  10. package/dist/cloudflare.js +179 -0
  11. package/dist/computerd-linux-amd64 +0 -0
  12. package/dist/computerd-linux-arm64 +0 -0
  13. package/dist/computerd.json +2 -2
  14. package/dist/conformance/boxd.d.ts +77 -0
  15. package/dist/conformance/boxd.js +113 -0
  16. package/dist/conformance/cases/isolation.js +1 -17
  17. package/dist/conformance/cloudflare.d.ts +42 -0
  18. package/dist/conformance/cloudflare.js +54 -0
  19. package/dist/conformance/dial-only.d.ts +6 -0
  20. package/dist/conformance/dial-only.js +9 -0
  21. package/dist/conformance/e2b.d.ts +12 -3
  22. package/dist/conformance/e2b.js +21 -4
  23. package/dist/conformance/fly.d.ts +52 -0
  24. package/dist/conformance/fly.js +52 -0
  25. package/dist/conformance/modal.d.ts +15 -2
  26. package/dist/conformance/modal.js +36 -3
  27. package/dist/conformance/morph.d.ts +59 -0
  28. package/dist/conformance/morph.js +95 -0
  29. package/dist/conformance/phone-harness.js +2 -2
  30. package/dist/conformance/runner.js +3 -3
  31. package/dist/conformance/sweep.d.ts +1 -6
  32. package/dist/conformance/sweep.js +8 -18
  33. package/dist/descriptors/boxd.d.ts +52 -0
  34. package/dist/descriptors/boxd.js +29 -0
  35. package/dist/descriptors/cloudflare.d.ts +21 -0
  36. package/dist/descriptors/cloudflare.js +29 -0
  37. package/dist/descriptors/e2b.d.ts +4 -0
  38. package/dist/descriptors/e2b.js +3 -0
  39. package/dist/descriptors/fly.d.ts +19 -0
  40. package/dist/descriptors/fly.js +28 -0
  41. package/dist/descriptors/index.d.ts +113 -1
  42. package/dist/descriptors/index.js +7 -2
  43. package/dist/descriptors/modal.d.ts +3 -0
  44. package/dist/descriptors/modal.js +7 -2
  45. package/dist/descriptors/morph.d.ts +15 -0
  46. package/dist/descriptors/morph.js +21 -0
  47. package/dist/descriptors/phone-harness.d.ts +1 -0
  48. package/dist/descriptors/phone-harness.js +2 -0
  49. package/dist/e2b.d.ts +7 -1
  50. package/dist/e2b.js +87 -44
  51. package/dist/fly.d.ts +43 -0
  52. package/dist/fly.js +245 -0
  53. package/dist/host.d.ts +8 -28
  54. package/dist/hosted/process.d.ts +19 -0
  55. package/dist/hosted/process.js +28 -0
  56. package/dist/hosted/provider.d.ts +11 -22
  57. package/dist/hosted/provider.js +30 -201
  58. package/dist/hosted/scripts.d.ts +2 -8
  59. package/dist/hosted/scripts.js +2 -22
  60. package/dist/hosted/ssh-exec.d.ts +2 -1
  61. package/dist/hosted/ssh-exec.js +58 -2
  62. package/dist/hosted/values.d.ts +5 -0
  63. package/dist/hosted/values.js +9 -0
  64. package/dist/index.d.ts +1 -1
  65. package/dist/index.js +2 -2
  66. package/dist/modal.d.ts +6 -0
  67. package/dist/modal.js +20 -10
  68. package/dist/morph.d.ts +65 -0
  69. package/dist/morph.js +495 -0
  70. package/dist/phone-harness.d.ts +15 -5
  71. package/dist/phone-harness.js +50 -15
  72. package/dist/screen-watch.js +2 -2
  73. package/package.json +20 -2
@@ -1,11 +1,15 @@
1
1
  import { AGENT37 } from "./agent37.js";
2
+ import { BOXD } from "./boxd.js";
2
3
  import { BROWSERBASE } from "./browserbase.js";
4
+ import { CLOUDFLARE } from "./cloudflare.js";
3
5
  import { DAYTONA } from "./daytona.js";
4
6
  import { DOCKER } from "./docker.js";
5
7
  import { E2B } from "./e2b.js";
8
+ import { FLY } from "./fly.js";
6
9
  import { KERNEL } from "./kernel.js";
7
10
  import { LOCAL } from "./local-chrome.js";
8
11
  import { MODAL } from "./modal.js";
12
+ import { MORPH } from "./morph.js";
9
13
  import { ORGO } from "./orgo.js";
10
14
  import { PHONE_HARNESS } from "./phone-harness.js";
11
15
  export declare const DESCRIPTORS: readonly [{
@@ -92,6 +96,9 @@ export declare const DESCRIPTORS: readonly [{
92
96
  readonly name: "modalApp";
93
97
  readonly option: "app";
94
98
  readonly default: "agentrun";
99
+ }, {
100
+ readonly name: "modalConnect";
101
+ readonly option: "connect";
95
102
  }];
96
103
  readonly metered: true;
97
104
  readonly mounts: readonly ["archil"];
@@ -117,6 +124,10 @@ export declare const DESCRIPTORS: readonly [{
117
124
  readonly option: "apiKey";
118
125
  readonly required: true;
119
126
  }];
127
+ readonly settings: readonly [{
128
+ readonly name: "e2bConnect";
129
+ readonly option: "connect";
130
+ }];
120
131
  readonly metered: true;
121
132
  readonly mounts: readonly ["archil"];
122
133
  readonly network: readonly ["none", "open", "allow"];
@@ -153,6 +164,56 @@ export declare const DESCRIPTORS: readonly [{
153
164
  }];
154
165
  readonly prepareImage: true;
155
166
  readonly load: () => Promise<typeof import("../agent37.js")>;
167
+ }, {
168
+ readonly id: "morph";
169
+ readonly label: "Morph";
170
+ readonly keys: readonly [{
171
+ readonly name: "MORPH_API_KEY";
172
+ readonly option: "apiKey";
173
+ readonly required: true;
174
+ }];
175
+ readonly metered: true;
176
+ readonly mounts: readonly [];
177
+ readonly network: readonly ["none", "open", "allow"];
178
+ readonly capabilities: readonly [import("../kinds.js").KindCapabilities];
179
+ readonly prepareImage: true;
180
+ readonly load: () => Promise<typeof import("../morph.js")>;
181
+ }, {
182
+ readonly id: "cloudflare";
183
+ readonly label: "Cloudflare";
184
+ readonly keys: readonly [{
185
+ readonly name: "CLOUDFLARE_RELAY_URL";
186
+ readonly option: "relayUrl";
187
+ readonly required: true;
188
+ }, {
189
+ readonly name: "CLOUDFLARE_RELAY_TOKEN";
190
+ readonly option: "relayToken";
191
+ readonly required: true;
192
+ }];
193
+ readonly metered: true;
194
+ readonly mounts: readonly [];
195
+ readonly network: readonly ["none", "open", "allow"];
196
+ readonly capabilities: readonly [import("../kinds.js").KindCapabilities];
197
+ readonly prepareImage: true;
198
+ readonly load: () => Promise<typeof import("../cloudflare.js")>;
199
+ }, {
200
+ readonly id: "fly";
201
+ readonly label: "Fly Machines";
202
+ readonly keys: readonly [{
203
+ readonly name: "FLY_API_TOKEN";
204
+ readonly option: "apiToken";
205
+ readonly required: true;
206
+ }, {
207
+ readonly name: "FLY_APP";
208
+ readonly option: "app";
209
+ readonly required: true;
210
+ }];
211
+ readonly metered: true;
212
+ readonly mounts: readonly [];
213
+ readonly network: readonly ["none", "open", "allow"];
214
+ readonly capabilities: readonly [import("../kinds.js").KindCapabilities];
215
+ readonly prepareImage: true;
216
+ readonly load: () => Promise<typeof import("../fly.js")>;
156
217
  }, {
157
218
  readonly id: "orgo";
158
219
  readonly label: "Orgo";
@@ -230,6 +291,7 @@ export declare const DESCRIPTORS: readonly [{
230
291
  readonly from: "Android platform-tools";
231
292
  readonly builds: readonly ["linux-x64", "darwin-x64", "darwin-arm64", "win32-x64"];
232
293
  };
294
+ readonly hostEnv: readonly ["PHONE_HARNESS_APKS"];
233
295
  readonly load: () => Promise<typeof import("../phone-harness.js")>;
234
296
  }, {
235
297
  readonly id: "browserbase";
@@ -291,9 +353,59 @@ export declare const DESCRIPTORS: readonly [{
291
353
  };
292
354
  readonly hostEnv: readonly ["PI_BROWSER_CHROME", "CHROME_PATH", "PATH"];
293
355
  readonly load: () => Promise<typeof import("../local-chrome.js")>;
356
+ }, {
357
+ readonly id: "boxd";
358
+ readonly label: "boxd";
359
+ readonly keys: readonly [{
360
+ readonly name: "BOXD_API_KEY";
361
+ readonly option: "apiKey";
362
+ readonly required: true;
363
+ }, {
364
+ readonly name: "BOXD_ORG";
365
+ readonly option: "org";
366
+ readonly required: false;
367
+ }, {
368
+ readonly name: "BOXD_REGION";
369
+ readonly option: "region";
370
+ readonly required: false;
371
+ }];
372
+ readonly metered: true;
373
+ readonly mounts: readonly [];
374
+ readonly network: readonly ["none"];
375
+ readonly capabilities: readonly [{
376
+ readonly options: {
377
+ readonly kind: "linux";
378
+ };
379
+ readonly kind: import("../protocol.js").ComputerKind;
380
+ readonly groups: import("../protocol.js").Group[];
381
+ readonly gpu?: import("../provider.js").GpuCapability;
382
+ readonly persistence?: {
383
+ keepsState: true;
384
+ resume: boolean;
385
+ };
386
+ readonly image?: string;
387
+ }, {
388
+ readonly options: {
389
+ readonly kind: "desktop";
390
+ };
391
+ readonly kind: import("../protocol.js").ComputerKind;
392
+ readonly groups: import("../protocol.js").Group[];
393
+ readonly gpu?: import("../provider.js").GpuCapability;
394
+ readonly persistence?: {
395
+ keepsState: true;
396
+ resume: boolean;
397
+ };
398
+ readonly image?: string;
399
+ }];
400
+ readonly defaultImage: {
401
+ readonly sandbox: "default";
402
+ };
403
+ readonly prepareImage: true;
404
+ readonly load: () => Promise<typeof import("../boxd.js")>;
294
405
  }];
295
- export { AGENT37, BROWSERBASE, DAYTONA, DOCKER, E2B, KERNEL, LOCAL, MODAL, ORGO, PHONE_HARNESS };
406
+ export { AGENT37, BOXD, BROWSERBASE, CLOUDFLARE, DAYTONA, DOCKER, E2B, FLY, KERNEL, LOCAL, MODAL, MORPH, ORGO, PHONE_HARNESS };
296
407
  export { AGENT37_BASE_TEMPLATE } from "./agent37.js";
408
+ export { BOXD_DEFAULT_IMAGE } from "./boxd.js";
297
409
  export { DAYTONA_DEFAULT_SNAPSHOT, DAYTONA_GPU_SNAPSHOT, type DaytonaGpuSnapshot, daytonaGpu, daytonaGpuSnapshot } from "./daytona.js";
298
410
  export { ORGO_BASE_IMAGE } from "./orgo.js";
299
411
  export { PHONE_GROUPS, PHONE_IMAGE } from "./phone-harness.js";
@@ -1,18 +1,23 @@
1
1
  // Every built-in provider's descriptor, in the order Settings shows them. Importing this loads descriptors (data) alone:
2
2
  // each provider module loads only when its descriptor's load() is called.
3
3
  import { AGENT37 } from "./agent37.js";
4
+ import { BOXD } from "./boxd.js";
4
5
  import { BROWSERBASE } from "./browserbase.js";
6
+ import { CLOUDFLARE } from "./cloudflare.js";
5
7
  import { DAYTONA } from "./daytona.js";
6
8
  import { DOCKER } from "./docker.js";
7
9
  import { E2B } from "./e2b.js";
10
+ import { FLY } from "./fly.js";
8
11
  import { KERNEL } from "./kernel.js";
9
12
  import { LOCAL } from "./local-chrome.js";
10
13
  import { MODAL } from "./modal.js";
14
+ import { MORPH } from "./morph.js";
11
15
  import { ORGO } from "./orgo.js";
12
16
  import { PHONE_HARNESS } from "./phone-harness.js";
13
- export const DESCRIPTORS = [DOCKER, DAYTONA, MODAL, E2B, AGENT37, ORGO, PHONE_HARNESS, BROWSERBASE, KERNEL, LOCAL];
14
- export { AGENT37, BROWSERBASE, DAYTONA, DOCKER, E2B, KERNEL, LOCAL, MODAL, ORGO, PHONE_HARNESS };
17
+ export const DESCRIPTORS = [DOCKER, DAYTONA, MODAL, E2B, AGENT37, MORPH, CLOUDFLARE, FLY, ORGO, PHONE_HARNESS, BROWSERBASE, KERNEL, LOCAL, BOXD];
18
+ export { AGENT37, BOXD, BROWSERBASE, CLOUDFLARE, DAYTONA, DOCKER, E2B, FLY, KERNEL, LOCAL, MODAL, MORPH, ORGO, PHONE_HARNESS };
15
19
  export { AGENT37_BASE_TEMPLATE } from "./agent37.js";
20
+ export { BOXD_DEFAULT_IMAGE } from "./boxd.js";
16
21
  export { DAYTONA_DEFAULT_SNAPSHOT, DAYTONA_GPU_SNAPSHOT, daytonaGpu, daytonaGpuSnapshot } from "./daytona.js";
17
22
  export { ORGO_BASE_IMAGE } from "./orgo.js";
18
23
  export { PHONE_GROUPS, PHONE_IMAGE } from "./phone-harness.js";
@@ -30,6 +30,9 @@ export declare const MODAL: {
30
30
  readonly name: "modalApp";
31
31
  readonly option: "app";
32
32
  readonly default: "agentrun";
33
+ }, {
34
+ readonly name: "modalConnect";
35
+ readonly option: "connect";
33
36
  }];
34
37
  readonly metered: true;
35
38
  readonly mounts: readonly ["archil"];
@@ -34,8 +34,13 @@ export const MODAL = defineProvider({
34
34
  { name: "MODAL_TOKEN_ID", option: "tokenId", required: true },
35
35
  { name: "MODAL_TOKEN_SECRET", option: "tokenSecret", required: true },
36
36
  ],
37
- // The Modal app its computers live in: the server's own when its settings name none.
38
- settings: [{ name: "modalApp", option: "app", default: "agentrun" }],
37
+ // The Modal app its computers live in: the server's own when its settings name none. How the server reaches its
38
+ // machines: exec (the provider's default, when the settings name none), a bridge through Modal's exec per
39
+ // connection, or dial, the machine dials the server.
40
+ settings: [
41
+ { name: "modalApp", option: "app", default: "agentrun" },
42
+ { name: "modalConnect", option: "connect" },
43
+ ],
39
44
  metered: true,
40
45
  mounts: ["archil"],
41
46
  // None: its programs run in a network of their own, their loopback alone (isolation.ts), and the sandbox is made with
@@ -0,0 +1,15 @@
1
+ export declare const MORPH: {
2
+ readonly id: "morph";
3
+ readonly label: "Morph";
4
+ readonly keys: readonly [{
5
+ readonly name: "MORPH_API_KEY";
6
+ readonly option: "apiKey";
7
+ readonly required: true;
8
+ }];
9
+ readonly metered: true;
10
+ readonly mounts: readonly [];
11
+ readonly network: readonly ["none", "open", "allow"];
12
+ readonly capabilities: readonly [import("../kinds.js").KindCapabilities];
13
+ readonly prepareImage: true;
14
+ readonly load: () => Promise<typeof import("../morph.js")>;
15
+ };
@@ -0,0 +1,21 @@
1
+ // Morph Cloud's descriptor: a Linux sandbox on a Morph instance (a VM started from a snapshot). Every computer starts
2
+ // from the box image built in the key's own account as a Morph snapshot, which its prepareImage() makes once per recipe.
3
+ import { defineProvider } from "../descriptor.js";
4
+ import { SANDBOX } from "./shared.js";
5
+ export const MORPH = defineProvider({
6
+ id: "morph",
7
+ label: "Morph",
8
+ keys: [{ name: "MORPH_API_KEY", option: "apiKey", required: true }],
9
+ metered: true,
10
+ // None yet: Morph's guests have /dev/fuse (docs: documentation/instances/fuse), and Archil's client there is unproven.
11
+ mounts: [],
12
+ // Morph has no egress control at all (no network field in its OpenAPI): all three are ours. None: its programs run in
13
+ // a network of their own, their loopback alone (isolation.ts). Open and a list: their one way out is init's egress
14
+ // proxy, which reaches the public internet alone, and with a list its hosts alone (hosted/network.ts).
15
+ network: ["none", "open", "allow"],
16
+ capabilities: [SANDBOX],
17
+ // No default image: a Morph image is an account's own snapshot id, so every computer starts from the box snapshot
18
+ // its prepareImage() finds or builds in the key's account.
19
+ prepareImage: true,
20
+ load: () => import("../morph.js"),
21
+ });
@@ -29,5 +29,6 @@ export declare const PHONE_HARNESS: {
29
29
  readonly from: "Android platform-tools";
30
30
  readonly builds: readonly ["linux-x64", "darwin-x64", "darwin-arm64", "win32-x64"];
31
31
  };
32
+ readonly hostEnv: readonly ["PHONE_HARNESS_APKS"];
32
33
  readonly load: () => Promise<typeof import("../phone-harness.js")>;
33
34
  };
@@ -19,5 +19,7 @@ export const PHONE_HARNESS = defineProvider({
19
19
  // The phone is driven by adb from the server's machine (the module's adb option, adb on PATH by default). Google
20
20
  // builds platform-tools for x86-64 Linux, macOS and x86-64 Windows alone.
21
21
  hostCommand: { command: "adb", from: "Android platform-tools", builds: ["linux-x64", "darwin-x64", "darwin-arm64", "win32-x64"] },
22
+ // The APKs every phone installs, files on this machine each pinned by its sha256: the operator's setting alone.
23
+ hostEnv: ["PHONE_HARNESS_APKS"],
22
24
  load: () => import("../phone-harness.js"),
23
25
  });
package/dist/e2b.d.ts CHANGED
@@ -23,11 +23,17 @@ export interface E2BProviderOptions extends Omit<HostedOptions, "maxLifetimeMs">
23
23
  Sandbox: E2BSandboxClass;
24
24
  /** E2B's domain: the API is https://api.<domain>. Default e2b.app. */
25
25
  domain?: string;
26
- /** desktop (default): a template with an X server, started through the daemon; linux: no screen. */
26
+ /** desktop (default; linux on connect "dial"): a template with an X server, started through the daemon; linux: no screen. */
27
27
  kind?: "desktop" | "linux";
28
28
  /** The longest lifetime check takes: E2B Hobby's 1 h by default, Pro's 24 h at most. */
29
29
  maxLifetimeMs?: number;
30
30
  timeouts?: Partial<HostedTimeouts>;
31
+ /**
32
+ * exec (default): the daemon goes in through envd's file API and each connection is a bridge through envd's process
33
+ * stream. dial: create starts the box template's agentrun-dial once, and the machine dials the server (options.dial),
34
+ * which every connection goes over; kind linux alone.
35
+ */
36
+ connect?: "exec" | "dial";
31
37
  }
32
38
  /**
33
39
  * What create() takes: the provider's options, the SDK's Sandbox class optional (default the host's e2b package's).
package/dist/e2b.js CHANGED
@@ -3,7 +3,8 @@ import { E2B } from "./descriptors/e2b.js";
3
3
  import { DEADLINE_LABEL, show } from "./drift.js";
4
4
  import { HostError } from "./host.js";
5
5
  import { deadlineOf, HostedProvider, isoOf, MAX_LABEL, timeoutsOf } from "./hosted/provider.js";
6
- import { dateOf, DOMAIN, isWhole, sizeRefusals } from "./hosted/values.js";
6
+ import { AGENTRUN_DIAL, hostedCommands, shellLine } from "./hosted/scripts.js";
7
+ import { connectOf, dateOf, DOMAIN, isWhole, sizeRefusals } from "./hosted/values.js";
7
8
  import { PassThrough } from "node:stream";
8
9
  import { ok } from "./result.js";
9
10
  /** Not a literal, so no type checker or bundler resolves the SDK from this package. */
@@ -66,6 +67,21 @@ const ROOT_SHELL = "/bin/sh";
66
67
  const ROOT_SHELL_ARGS = ["-c", 'exec "$@"', "sh"];
67
68
  /** The PATH root's command runs with: the system's directories alone, none of /usr/local. */
68
69
  const ROOT_PATH = "/usr/sbin:/usr/bin:/sbin:/bin";
70
+ /** Where a dial machine's launch leaves what it and agentrun-dial write, root's alone: no exec reads it back. */
71
+ const DIAL_LOG = "/run/agentrun-dial.log";
72
+ /**
73
+ * A dial machine's launch, root's command with boot env: E2B runs a template's start command once, at the template's
74
+ * build, and snapshots it running, so it never sees a create's env (docs.e2b.dev/template/start-ready-command). So
75
+ * create starts agentrun-dial itself, after the steps the exec path runs before init: ROOT_ONLY made root's alone, the
76
+ * session buses in /tmp closed. A step that fails starts nothing, and the machine never dials.
77
+ */
78
+ const DIAL_LAUNCH = [
79
+ "-c",
80
+ [
81
+ `umask 077; exec >>${DIAL_LOG} 2>&1 </dev/null`,
82
+ `${shellLine(hostedCommands({ rootOnly: ROOT_ONLY }).rootOnly)} && ${shellLine(hostedCommands().sockets)} && exec ${AGENTRUN_DIAL}`,
83
+ ].join("\n"),
84
+ ];
69
85
  /** The SDK names its errors (index.mjs:86-360); Connect's carry a code. */
70
86
  function codeOf(error) {
71
87
  const name = error?.name;
@@ -115,27 +131,37 @@ const push = (stream, data) => void (stream.writableEnded || stream.write(data))
115
131
  /** E2B's sandboxes as a MachineHost (../host.ts). */
116
132
  class E2BHost {
117
133
  descriptor = E2B;
118
- facts = {
119
- daemon: "child",
120
- isolation: "microvm",
121
- lifetime: "vendor",
122
- maxLifetimeMs: PRO_MAX_MS,
123
- arch: "amd64",
124
- vendorAgentPorts: [ENVD_PORT],
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
- windowManager: true,
127
- // System paths whose permissions E2B's template build sets wider than root's, on its templates and ours alike.
128
- rootOnly: ROOT_ONLY,
129
- };
134
+ facts;
135
+ /** connect exec alone: a dial host has neither (HostFacts.connect). */
136
+ exec;
137
+ upload;
130
138
  #Sandbox;
131
139
  #connection;
132
140
  #requestMs;
133
141
  /** Each sandbox create or connect gave, by id, for envd's commands and files: let go of at its delete. */
134
142
  #sandboxes = new Map();
135
- constructor(Sandbox, connection, requestMs) {
143
+ constructor(Sandbox, connection, requestMs, connect) {
136
144
  this.#Sandbox = Sandbox;
137
145
  this.#connection = connection;
138
146
  this.#requestMs = requestMs;
147
+ this.facts = {
148
+ daemon: "child",
149
+ isolation: "microvm",
150
+ lifetime: "vendor",
151
+ maxLifetimeMs: PRO_MAX_MS,
152
+ arch: "amd64",
153
+ vendorAgentPorts: [ENVD_PORT],
154
+ // 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.
155
+ windowManager: true,
156
+ // System paths whose permissions E2B's template build sets wider than root's, on its templates and ours alike: the
157
+ // adapter's step on exec, the launch's on dial (DIAL_LAUNCH).
158
+ rootOnly: ROOT_ONLY,
159
+ ...(connect === "dial" ? { connect } : {}),
160
+ };
161
+ if (connect === "exec") {
162
+ this.exec = (id, argv, ctx) => this.#exec(id, argv, ctx);
163
+ this.upload = (id, path, bytes, ctx) => this.#upload(id, path, bytes, ctx);
164
+ }
139
165
  }
140
166
  errorCode(error) {
141
167
  return codeOf(error);
@@ -172,6 +198,11 @@ class E2BHost {
172
198
  };
173
199
  const sandbox = await this.#Sandbox.create(req.image, options);
174
200
  this.#sandboxes.set(sandbox.sandboxId, sandbox);
201
+ // A dial machine's launch: the boot env goes to agentrun-dial's process alone, never to the sandbox's envs, which
202
+ // envd gives every process it starts. The stream is let go of once envd started it: the process runs on
203
+ // (docs.e2b.dev/commands/background; the SDK's CommandHandle.disconnect, index.mjs:2760-2774).
204
+ if (req.boot !== undefined)
205
+ (await this.#process(sandbox, DIAL_LAUNCH, req.boot.env, false, ctx)).stream.abort();
175
206
  return { id: sandbox.sandboxId };
176
207
  }
177
208
  /** getInfo; a sandbox E2B does not have (SandboxNotFoundError, index.mjs:5431) is not_found, which the adapter reads as none. */
@@ -220,8 +251,8 @@ class E2BHost {
220
251
  this.#sandboxes.set(id, sandbox);
221
252
  return sandbox;
222
253
  }
223
- /** files.write as root (index.mjs:2332-2435). */
224
- async upload(id, path, bytes, ctx) {
254
+ /** files.write as root (index.mjs:2332-2435); connect exec alone. */
255
+ async #upload(id, path, bytes, ctx) {
225
256
  const sandbox = await this.#sandbox(id, ctx);
226
257
  const buffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
227
258
  await sandbox.files.write(path, buffer, { user: "root", requestTimeoutMs: ctx.timeoutMs, ...(ctx.signal ? { signal: ctx.signal } : {}) });
@@ -234,36 +265,12 @@ class E2BHost {
234
265
  * connect-web connect-transport.js:145-150), so envd never ends it (start.go:39-44); the start alone is bounded by
235
266
  * ctx. Writes go one sendStdin at a time, in order; end is closeStdin; kill SIGKILLs it and lets go of its stream.
236
267
  */
237
- async exec(id, argv, ctx) {
268
+ async #exec(id, argv, ctx) {
238
269
  const sandbox = await this.#sandbox(id, ctx);
239
270
  const out = new PassThrough();
240
271
  const err = new PassThrough();
241
272
  const requestTimeoutMs = this.#requestMs;
242
- const stream = new AbortController();
243
- const events = sandbox.commands.rpc.start({ process: { cmd: ROOT_SHELL, args: [...ROOT_SHELL_ARGS, ...argv], envs: { PATH: ROOT_PATH } }, stdin: true }, { headers: { Authorization: ROOT, [KEEPALIVE_HEADER]: KEEPALIVE_S }, signal: stream.signal, timeoutMs: 0 })[Symbol.asyncIterator]();
244
- // The start, within ctx: a stream that gives no start event in time, or the caller's abort, is let go of.
245
- const startAbort = () => stream.abort(ctx.signal?.reason);
246
- ctx.signal?.addEventListener("abort", startAbort, { once: true });
247
- const startTimer = setTimeout(() => stream.abort(), ctx.timeoutMs);
248
- let pid;
249
- try {
250
- const first = await events.next();
251
- const event = first.done ? undefined : first.value.event?.event;
252
- if (event?.case !== "start")
253
- throw new Error(`envd's process stream began with ${event?.case ?? "nothing"}, not its start`);
254
- pid = event.value.pid;
255
- }
256
- catch (error) {
257
- const why = stream.signal.aborted ? (ctx.signal?.aborted ? "AbortError" : "TimeoutError") : undefined;
258
- stream.abort();
259
- if (why === undefined)
260
- throw error;
261
- throw Object.assign(new Error(why === "AbortError" ? "the exec was aborted before envd started it" : `envd did not start the process within ${ctx.timeoutMs / 1000} s`), { name: why });
262
- }
263
- finally {
264
- clearTimeout(startTimer);
265
- ctx.signal?.removeEventListener("abort", startAbort);
266
- }
273
+ const { pid, events, stream } = await this.#process(sandbox, [...ROOT_SHELL_ARGS, ...argv], {}, true, ctx);
267
274
  const exited = (async () => {
268
275
  let code = -1;
269
276
  try {
@@ -307,6 +314,38 @@ class E2BHost {
307
314
  },
308
315
  };
309
316
  }
317
+ /**
318
+ * Root's /bin/sh with args, started through envd's Process.Start stream, with PATH the system's directories and env
319
+ * over it: its pid once envd started it within ctx, its events after the start, and the stream's abort.
320
+ */
321
+ async #process(sandbox, args, env, stdin, ctx) {
322
+ const stream = new AbortController();
323
+ const events = sandbox.commands.rpc.start({ process: { cmd: ROOT_SHELL, args: [...args], envs: { PATH: ROOT_PATH, ...env } }, stdin }, { headers: { Authorization: ROOT, [KEEPALIVE_HEADER]: KEEPALIVE_S }, signal: stream.signal, timeoutMs: 0 })[Symbol.asyncIterator]();
324
+ // The start, within ctx: a stream that gives no start event in time, or the caller's abort, is let go of.
325
+ const startAbort = () => stream.abort(ctx.signal?.reason);
326
+ ctx.signal?.addEventListener("abort", startAbort, { once: true });
327
+ const startTimer = setTimeout(() => stream.abort(), ctx.timeoutMs);
328
+ let pid;
329
+ try {
330
+ const first = await events.next();
331
+ const event = first.done ? undefined : first.value.event?.event;
332
+ if (event?.case !== "start")
333
+ throw new Error(`envd's process stream began with ${event?.case ?? "nothing"}, not its start`);
334
+ pid = event.value.pid;
335
+ }
336
+ catch (error) {
337
+ const why = stream.signal.aborted ? (ctx.signal?.aborted ? "AbortError" : "TimeoutError") : undefined;
338
+ stream.abort();
339
+ if (why === undefined)
340
+ throw error;
341
+ throw Object.assign(new Error(why === "AbortError" ? "the exec was aborted before envd started it" : `envd did not start the process within ${ctx.timeoutMs / 1000} s`), { name: why });
342
+ }
343
+ finally {
344
+ clearTimeout(startTimer);
345
+ ctx.signal?.removeEventListener("abort", startAbort);
346
+ }
347
+ return { pid, events, stream };
348
+ }
310
349
  /**
311
350
  * Moves E2B's timer (setTimeout, index.mjs:5529-5541) in the whole seconds E2B takes: up to clear create's end, so
312
351
  * the end reads as moved (deadlineOf), and down at the most the computer may live (its max-deadline label), so E2B's
@@ -357,7 +396,11 @@ export class E2BProvider extends HostedProvider {
357
396
  // A caller who still names the option is told it is gone, whatever its value: it once let public traffic in.
358
397
  if (typeof options === "object" && options !== null && Object.hasOwn(options, "publicStream"))
359
398
  throw new Error(PUBLIC);
360
- const { apiKey, Sandbox, domain = DEFAULT_DOMAIN, kind = "desktop", maxLifetimeMs = HOBBY_MAX_MS, ...rest } = options;
399
+ const { apiKey, Sandbox, domain = DEFAULT_DOMAIN, kind: named, maxLifetimeMs = HOBBY_MAX_MS, connect, ...rest } = options;
400
+ const via = connectOf(connect, "E2B");
401
+ // A server names connect alone (its e2bConnect setting): on dial the kind is linux unless named, since agentrun-dial
402
+ // starts init with no display; a desktop named on dial is the adapter's refusal.
403
+ const kind = named ?? (via === "dial" ? "linux" : "desktop");
361
404
  if (typeof apiKey !== "string" || apiKey === "")
362
405
  throw new Error("options.apiKey, the E2B API key, is required: the provider reads no environment, so the caller passes it");
363
406
  const lacks = ["create", "connect", "getInfo", "setTimeout", "kill", "list"].filter((name) => typeof Sandbox?.[name] !== "function");
@@ -368,6 +411,6 @@ export class E2BProvider extends HostedProvider {
368
411
  throw new Error(ambient);
369
412
  if (typeof domain !== "string" || !DOMAIN.test(domain))
370
413
  throw new Error(`the E2B domain must be a host name such as ${DEFAULT_DOMAIN}, not ${JSON.stringify(domain)}`);
371
- super(new E2BHost(Sandbox, connectionOptions({ apiKey, domain }), timeoutsOf(rest.timeouts).requestMs), { ...rest, kind, maxLifetimeMs });
414
+ super(new E2BHost(Sandbox, connectionOptions({ apiKey, domain }), timeoutsOf(rest.timeouts).requestMs, via), { ...rest, kind, maxLifetimeMs });
372
415
  }
373
416
  }
package/dist/fly.d.ts ADDED
@@ -0,0 +1,43 @@
1
+ import { HostedProvider, type HostedOptions, type HostedTimeouts } from "./hosted/provider.js";
2
+ import { type Result } from "./result.js";
3
+ /** One machine as the Machines API answers it (M, "Machine properties"; fly-go Machine), as far as this host reads it. */
4
+ export interface FlyMachine {
5
+ id: string;
6
+ state: string;
7
+ created_at?: string;
8
+ config?: {
9
+ metadata?: Record<string, string> | null;
10
+ } | null;
11
+ /** fly-go: the config rebuilt in part while host_status isn't "ok". */
12
+ incomplete_config?: {
13
+ metadata?: Record<string, string> | null;
14
+ } | null;
15
+ }
16
+ /** The Fly provider's options: the token and the app, then the shared adapter's (HostedOptions). */
17
+ export interface FlyProviderOptions extends Omit<HostedOptions, "kind" | "desktop" | "maxLifetimeMs"> {
18
+ /** A Fly API token that may make machines in the app. The caller passes it; this provider reads no environment. */
19
+ apiToken: string;
20
+ /** The Fly app the machines live in, made by the operator beforehand (fly apps create). */
21
+ app: string;
22
+ /** The fetch every call goes through; default the global one. */
23
+ fetch?: typeof fetch;
24
+ /** The longest lifetime check takes, in ms: at most 24 h, the janitor's cap, which is the default. */
25
+ maxLifetimeMs?: number;
26
+ timeouts?: Partial<HostedTimeouts>;
27
+ }
28
+ /** A FlyProvider from its options alone; it reads no environment (serve passes the saved FLY_API_TOKEN and FLY_APP). */
29
+ export declare function create(options: FlyProviderOptions): FlyProvider;
30
+ /** The conformance CLI's module for Fly Machines: its settings, and its dialKit that refuses off the public server. */
31
+ export declare const conformance: () => Promise<typeof import("./conformance/fly.js")>;
32
+ /**
33
+ * Computers that are Fly Machines, on the shared adapter, each dialing the server that made it: a server with no public
34
+ * https address (AGENTRUN_PUBLIC_URL) refuses a create in words before Fly is called. Kind linux alone.
35
+ */
36
+ export declare class FlyProvider extends HostedProvider {
37
+ /**
38
+ * The provider contract's prepareImage (its descriptor declares it): the box image the release publishes, by its
39
+ * public registry tag (box-image.ts). No call: Fly pulls config.image at each create.
40
+ */
41
+ prepareImage(): Promise<Result<string>>;
42
+ constructor(options: FlyProviderOptions);
43
+ }