@parcha/agentrun-computer 0.1.0-beta.52 → 0.1.0-beta.54

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.
package/dist/daytona.js CHANGED
@@ -1,11 +1,9 @@
1
1
  // The Daytona host: Daytona sandboxes over Daytona's v0 REST API with fetch (no SDK). Daytona's toolbox daemon is the
2
2
  // sandbox's first process, so computerd is a child: its upload goes through the toolbox's file API, and every command
3
3
  // (install, init's start, the stdio bridge, an Archil computer's root steps) is a session command, its output read from
4
- // the command's log stream and its stdin sent as the command's input. With connect "dial", the sandbox is made with the
5
- // boot env as its env, and the snapshot's entrypoint (box/build-daytona.py names the box image's CMD) runs agentrun-dial
6
- // in the toolbox's entrypoint session: the machine dials the server, with no upload and no session command. The rest of
7
- // the computer is the shared machine-host adapter's (./hosted/provider.ts). Every Daytona fact used here is cited in the
8
- // README's Daytona section.
4
+ // the command's log stream and its stdin sent as the command's input. With connect dial, create starts agentrun-dial
5
+ // itself in a toolbox session (README, Daytona on dial). The rest of the computer is the shared machine-host adapter's
6
+ // (./hosted/provider.ts). Every Daytona fact used here is cited in the README's Daytona section.
9
7
  import { randomBytes } from "node:crypto";
10
8
  import { connectOf, kindRefusal, mountsOf } from "./descriptor.js";
11
9
  import { DAYTONA, DAYTONA_DEFAULT_SNAPSHOT, DAYTONA_GPU, DAYTONA_GPU_REGION, DAYTONA_GPU_SNAPSHOT, daytonaGpuSnapshot } from "./descriptors/daytona.js";
@@ -13,13 +11,22 @@ import { COMPUTER_LABEL } from "./drift.js";
13
11
  import { HostError } from "./host.js";
14
12
  import { framedExec } from "./hosted/framed-exec.js";
15
13
  import { HostedProvider, timeoutsOf } from "./hosted/provider.js";
16
- import { boundOf, orThrow, pause as sleep } from "./hosted/process.js";
14
+ import { boundOf, orThrow, seconds, pause as sleep, words } from "./hosted/process.js";
17
15
  import { allPages, jsonOf, rest } from "./hosted/rest.js";
18
- import { shellLine } from "./hosted/scripts.js";
16
+ import { dialLaunch, shellLine } from "./hosted/scripts.js";
19
17
  import { dateOf, isWhole, sizeRefusals } from "./hosted/values.js";
20
18
  import { MAX_LINE_BYTES } from "./protocol.js";
21
19
  import { checkGpu } from "./provider.js";
22
20
  import { ok, vendorFail } from "./result.js";
21
+ /** options.listedMs as a whole number of ms above 0 (a number, or its digits as DAYTONA_LISTED_MS gives them), or undefined when unset. */
22
+ function listedMsOf(value) {
23
+ if (value === undefined || value === "")
24
+ return undefined;
25
+ const ms = typeof value === "string" && /^\s*\d+\s*$/.test(value) ? Number(value) : value;
26
+ if (!isWhole(ms) || ms <= 0)
27
+ throw new Error(`listedMs (DAYTONA_LISTED_MS) is a whole number of ms above 0, not ${JSON.stringify(value)}`);
28
+ return ms;
29
+ }
23
30
  /** A positive finite figure of Daytona's answer, else undefined (absent, zero or not a number: never guessed). */
24
31
  const given = (value) => (typeof value === "number" && Number.isFinite(value) && value > 0 ? value : undefined);
25
32
  /** What Daytona says a sandbox was given (Machine.resources): its CPUs, its memory (GiB, as MB), its disk (GiB) and its
@@ -64,6 +71,8 @@ const OUT = Buffer.from([1, 1, 1]);
64
71
  const ERR = Buffer.from([2, 2, 2]);
65
72
  /** A line the client wrote, echoed back: a request or a notification is never a daemon's reply. */
66
73
  const ECHO = /^\{"jsonrpc":"2\.0",("id":\d+,)?"method":/;
74
+ /** The toolbox session a dial sandbox's agentrun-dial runs in, its one command: dialLog reads its log by this id. */
75
+ const DIAL_SESSION = "agentrun-dial";
67
76
  const decoder = new TextDecoder();
68
77
  /**
69
78
  * Why a dial computer takes no GPU: check() refuses one in these words, and capabilities() declares none on dial.
@@ -121,6 +130,10 @@ class DaytonaHost {
121
130
  /** connect exec alone: a dial host has neither (HostFacts.connect). */
122
131
  exec;
123
132
  upload;
133
+ /** connect dial alone: agentrun-dial's session command's log. */
134
+ dialLog;
135
+ /** The command that runs agentrun-dial, by sandbox id, from its create: what dialLog reads. Let go of at its delete. */
136
+ #dials = new Map();
124
137
  /** Daytona's REST API: the control plane, and the toolbox of each sandbox. */
125
138
  #rest;
126
139
  #headers;
@@ -148,7 +161,7 @@ class DaytonaHost {
148
161
  // its own. The toolbox listens on 2280 on every interface and runs commands for whoever reaches it, so init starts
149
162
  // with --own-network, and network none is all a computer takes. Its D-Bus session bus in /tmp (/tmp/dbus-*), which
150
163
  // no network namespace cuts, is closed to the tool user before init starts, as on every child host. On dial init is
151
- // agentrun-dial's child, and agentrun-dial the entrypoint the toolbox runs in a session of its own: still a child.
164
+ // agentrun-dial's child, and agentrun-dial a session command create starts through the toolbox: still a child.
152
165
  this.facts = {
153
166
  daemon: "child",
154
167
  isolation: options.sandboxClass === "linux-vm" ? "vm" : "container",
@@ -166,6 +179,8 @@ class DaytonaHost {
166
179
  this.exec = (id, argv, ctx) => this.#exec(id, argv, ctx);
167
180
  this.upload = (id, path, bytes, ctx) => this.#upload(id, path, bytes, ctx);
168
181
  }
182
+ else
183
+ this.dialLog = (id, ctx) => this.#dialLog(id, ctx);
169
184
  }
170
185
  /**
171
186
  * A snapshot name has no control characters, and its size is the snapshot's; a GPU computer is made from the
@@ -214,16 +229,19 @@ class DaytonaHost {
214
229
  * races it, and deletes by name one whose answer never comes. A name Daytona already holds (409) made nothing: exists,
215
230
  * and the adapter adopts the sandbox the name lists, as a retry does. req.backstopAt is left: the TTL is Daytona's own
216
231
  * timer at the deadline (lifetime "vendor"), and autoDeleteInterval counts from a stop, not from create. A dial
217
- * machine's boot env is the sandbox's env, which the toolbox's entrypoint session inherits (README, Daytona on dial).
232
+ * machine's boot env but AGENTRUN_ATTACH_URL is the sandbox's env, which every session command inherits, and create
233
+ * then starts agentrun-dial within ctx.timeoutMs (#startDial; README, Daytona on dial).
218
234
  */
219
235
  async create(req, ctx) {
236
+ const until = Date.now() + ctx.timeoutMs;
220
237
  const gpu = req.gpu !== undefined;
238
+ const { AGENTRUN_ATTACH_URL: attach, ...env } = req.boot?.env ?? {};
221
239
  const body = {
222
240
  name: req.name,
223
241
  // "default" sends no snapshot, and Daytona makes the sandbox from its default snapshot.
224
242
  ...(gpu ? { snapshot: this.#gpu.snapshot } : req.image === DAYTONA_DEFAULT_SNAPSHOT ? {} : { snapshot: req.image }),
225
243
  labels: { ...req.labels },
226
- env: { ...req.boot?.env },
244
+ env,
227
245
  public: false,
228
246
  // A GPU sandbox runs in region earth alone, whatever the provider's target.
229
247
  ...(gpu ? { target: DAYTONA_GPU_REGION } : this.#target === undefined ? {} : { target: this.#target }),
@@ -238,11 +256,61 @@ class DaytonaHost {
238
256
  // GPU is the snapshot's, held by the adapter's GPU label.
239
257
  };
240
258
  const posted = await this.#rest.json("POST", sandboxUrl(this.#rest), { json: body, timeoutMs: ctx.timeoutMs, named: true });
241
- const id = orThrow(posted)?.id;
259
+ const sb = orThrow(posted);
260
+ const id = sb?.id;
242
261
  if (typeof id !== "string" || id === "")
243
262
  throw new Error("POST /sandbox: no sandbox id in the answer");
263
+ if (req.boot !== undefined)
264
+ await this.#startDial(sb, attach ?? "", until, ctx.timeoutMs);
244
265
  return { id };
245
266
  }
267
+ /**
268
+ * A dial sandbox's agentrun-dial, started once the sandbox reads started (by `until`, ms after create began): one
269
+ * toolbox session of its own (DIAL_SESSION), its one command async: dialLaunch's line, as root (the toolbox runs
270
+ * session commands as root), AGENTRUN_ATTACH_URL a quoted assignment on it. The token is never on it: it stays in the
271
+ * sandbox's env, which the command inherits. The session and the command's id are kept, so its log is the dial's last
272
+ * words (dialLog). A sandbox gone as a machine reads (stateOf: failed, destroying or asked to destroy), or a session or
273
+ * command Daytona refuses, throws vendor in Daytona's words, and one not started by `until` throws timeout: either is
274
+ * a create that made a machine to the adapter, which deletes it by its name.
275
+ */
276
+ async #startDial(posted, attach, until, timeoutMs) {
277
+ const { id } = posted;
278
+ let sb = posted;
279
+ for (let state = stateOf(sb); state !== "running"; state = stateOf(sb)) {
280
+ if (state === "gone")
281
+ throw new HostError("vendor", `Daytona reads the sandbox ${id} ${sb.state}${sb.desiredState === "destroyed" ? ", to be destroyed" : ""}, so agentrun-dial was not started: ${sb.errorReason || "no reason given"}`);
282
+ if (Date.now() + this.#pollMs >= until)
283
+ throw new HostError("timeout", `the sandbox ${id} did not read started within ${seconds(timeoutMs)} (it reads ${sb.state ?? "no state"}), so agentrun-dial was not started`);
284
+ await sleep(this.#pollMs);
285
+ const read = await sandboxOf(this.#rest, id);
286
+ if (!read.ok)
287
+ throw new HostError("vendor", `reading the sandbox ${id} while it starts failed: ${read.error.message}`);
288
+ if (read.value === undefined)
289
+ throw new HostError("vendor", `Daytona no longer has the sandbox ${id}, so agentrun-dial was not started`);
290
+ sb = read.value;
291
+ }
292
+ try {
293
+ const toolbox = await this.#toolbox(id);
294
+ const { commandId } = await this.#runAsync(toolbox, DIAL_SESSION, dialLaunch({ rootOnly: this.facts.rootOnly, attach }), Math.max(1, until - Date.now()));
295
+ this.#dials.set(id, commandId);
296
+ }
297
+ catch (error) {
298
+ throw new HostError("vendor", `starting agentrun-dial in ${id} failed: ${words(error)}`);
299
+ }
300
+ }
301
+ /**
302
+ * What agentrun-dial wrote: one read of the log of the command create started. The toolbox answers a client that names
303
+ * no SDK version with the log as written, each write behind its stream's prefix (README, Daytona on dial), and the
304
+ * prefixes are dropped. undefined when this host started no agentrun-dial there.
305
+ */
306
+ async #dialLog(id, ctx) {
307
+ const commandId = this.#dials.get(id);
308
+ if (commandId === undefined)
309
+ return undefined;
310
+ const session = `${await this.#toolbox(id, ctx.signal)}/process/session/${DIAL_SESSION}`;
311
+ const logs = orThrow(await this.#rest.call("GET", `${session}/command/${encodeURIComponent(commandId)}/logs`, { retry: true, timeoutMs: ctx.timeoutMs }, ctx.signal));
312
+ return decoder.decode(logs.bytes).replaceAll(OUT.toString("latin1"), "").replaceAll(ERR.toString("latin1"), "");
313
+ }
246
314
  /** GET /sandbox/{id}; one Daytona answers 404 for, or reads destroyed, is none. */
247
315
  async get(id, ctx) {
248
316
  const found = orThrow(await sandboxOf(this.#rest, id, ctx.signal));
@@ -282,6 +350,7 @@ class DaytonaHost {
282
350
  */
283
351
  async delete(id, ctx) {
284
352
  this.#toolboxes.delete(id);
353
+ this.#dials.delete(id);
285
354
  let failure;
286
355
  for (let attempt = 1; attempt <= DELETE_ATTEMPTS; attempt++) {
287
356
  const removed = await this.#rest.call("DELETE", sandboxUrl(this.#rest, id), { retry: true, timeoutMs: ctx.timeoutMs });
@@ -388,16 +457,23 @@ class DaytonaHost {
388
457
  },
389
458
  };
390
459
  }
391
- async #startCommand(toolbox, argv, ctx) {
392
- const sessionId = `agentrun-${randomBytes(8).toString("hex")}`;
460
+ /**
461
+ * A session of its own (sessionId) in the toolbox, with one command run in it async, no input echo: its session's URL
462
+ * and the command's id. A command Daytona does not take removes the session again.
463
+ */
464
+ async #runAsync(toolbox, sessionId, command, timeoutMs, signal) {
393
465
  const session = `${toolbox}/process/session/${sessionId}`;
394
- orThrow(await this.#rest.call("POST", `${toolbox}/process/session`, { json: { sessionId }, timeoutMs: ctx.timeoutMs }, ctx.signal));
395
- const ran = await this.#rest.json("POST", `${session}/exec`, { json: { command: shellLine(argv), runAsync: true, suppressInputEcho: true }, timeoutMs: ctx.timeoutMs }, ctx.signal);
466
+ orThrow(await this.#rest.call("POST", `${toolbox}/process/session`, { json: { sessionId }, timeoutMs }, signal));
467
+ const ran = await this.#rest.json("POST", `${session}/exec`, { json: { command, runAsync: true, suppressInputEcho: true }, timeoutMs }, signal);
396
468
  const commandId = ran.ok ? ran.value?.cmdId : undefined;
397
469
  if (!ran.ok || typeof commandId !== "string") {
398
470
  await this.#rest.call("DELETE", session, {});
399
471
  throw ran.ok ? new Error("POST exec: no command id in the answer") : new HostError(ran.error.code, ran.error.message);
400
472
  }
473
+ return { session, commandId };
474
+ }
475
+ async #startCommand(toolbox, argv, ctx) {
476
+ const { session, commandId } = await this.#runAsync(toolbox, `agentrun-${randomBytes(8).toString("hex")}`, shellLine(argv), ctx.timeoutMs, ctx.signal);
401
477
  let socket;
402
478
  try {
403
479
  socket = this.#webSocket(`${session.replace(/^https:/, "wss:")}/command/${encodeURIComponent(commandId)}/logs?follow=true`, { headers: this.#headers, protocols: [] });
@@ -530,7 +606,7 @@ class DaytonaHost {
530
606
  */
531
607
  export class DaytonaProvider extends HostedProvider {
532
608
  constructor(options) {
533
- const { apiKey, apiUrl = DEFAULT_API_URL, arch = "amd64", sandboxClass = "container", target, gpuSnapshot, autoStopMinutes = 0, autoDeleteMinutes, connect, fetch: fetcher, webSocket, pause, timeouts = {}, ...hosted } = options ?? {};
609
+ const { apiKey, apiUrl = DEFAULT_API_URL, arch = "amd64", sandboxClass = "container", target, gpuSnapshot, autoStopMinutes = 0, autoDeleteMinutes, connect, fetch: fetcher, webSocket, pause, timeouts = {}, listedMs, ...hosted } = options ?? {};
534
610
  const via = connectOf(DAYTONA, { connect });
535
611
  const refused = kindRefusal(DAYTONA, { kind: hosted.kind, connect: via });
536
612
  if (refused !== undefined)
@@ -551,7 +627,9 @@ export class DaytonaProvider extends HostedProvider {
551
627
  minutes("autoStopMinutes", autoStopMinutes);
552
628
  if (autoDeleteMinutes !== undefined)
553
629
  minutes("autoDeleteMinutes", autoDeleteMinutes);
554
- const { retryMs = DEFAULT_RETRY_MS, ...hostedTimeouts } = timeouts;
630
+ const listed = listedMsOf(listedMs);
631
+ const { retryMs = DEFAULT_RETRY_MS, ...asked } = timeouts;
632
+ const hostedTimeouts = { ...(listed === undefined ? {} : { listedMs: listed }), ...asked };
555
633
  if (!isWhole(retryMs) || retryMs <= 0)
556
634
  throw new Error(`timeouts.retryMs must be a whole number of ms above 0, not ${retryMs}`);
557
635
  const { requestMs, pollMs } = timeoutsOf(hostedTimeouts);
@@ -73,6 +73,10 @@ export declare const DAYTONA: {
73
73
  readonly name: "DAYTONA_ATTACH_EGRESS";
74
74
  readonly option: "attachEgress";
75
75
  readonly required: false;
76
+ }, {
77
+ readonly name: "DAYTONA_LISTED_MS";
78
+ readonly option: "listedMs";
79
+ readonly required: false;
76
80
  }];
77
81
  readonly settings: readonly [{
78
82
  readonly name: "daytonaConnect";
@@ -77,6 +77,8 @@ export const DAYTONA = defineProvider({
77
77
  { name: "DAYTONA_TARGET", option: "target", required: false },
78
78
  { name: DAYTONA_ARCHIL_EGRESS, option: "archilEgress", required: false },
79
79
  { name: DAYTONA_ATTACH_EGRESS, option: "attachEgress", required: false },
80
+ // How long create waits for the label listing, in ms (DaytonaProviderOptions.listedMs): no secret, a tuning.
81
+ { name: "DAYTONA_LISTED_MS", option: "listedMs", required: false },
80
82
  ],
81
83
  // How the server reaches its machines: exec (the provider's default, when the server's settings name none), a session
82
84
  // command through the toolbox per connection, or dial, the machine dials the server (a snapshot of box/Dockerfile).
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The name of Groundbox's own image: no template and no image is sent, so Groundbox starts the team's default template
3
+ * when it has one, else its own image (Ubuntu 24.04 with the usual tools). Groundbox reserves the name, so no template
4
+ * can hold it. Not the provider's default: that image keeps toolchains under /opt deeper than the isolation probe
5
+ * searches, so the socket fence can't be proven on it.
6
+ */
7
+ export declare const GROUNDBOX_OWN_IMAGE = "default";
8
+ export declare const GROUNDBOX: {
9
+ readonly id: "groundbox";
10
+ readonly label: "Groundbox";
11
+ readonly keys: readonly [{
12
+ readonly name: "GROUNDBOX_API_KEY";
13
+ readonly option: "apiKey";
14
+ readonly required: true;
15
+ }];
16
+ readonly metered: true;
17
+ readonly mounts: readonly [];
18
+ readonly network: readonly ["none", "open", "allow"];
19
+ readonly capabilities: readonly [import("../kinds.js").KindCapabilities, {
20
+ readonly options: {
21
+ readonly kind: "desktop";
22
+ };
23
+ readonly kind: import("../protocol.js").ComputerKind;
24
+ readonly groups: import("../protocol.js").Group[];
25
+ readonly gpu?: import("../provider.js").GpuCapability;
26
+ readonly persistence?: {
27
+ keepsState: true;
28
+ resume: boolean;
29
+ };
30
+ readonly image?: string;
31
+ }];
32
+ readonly prepareImage: true;
33
+ readonly load: () => Promise<typeof import("../groundbox.js")>;
34
+ };
@@ -0,0 +1,30 @@
1
+ // Groundbox's descriptor: a Linux sandbox on a Groundbox sandbox (a Firecracker microVM), started from our box image, the
2
+ // public registry tag its prepareImage() answers (box-image.ts), which Groundbox turns into a disk at the first create.
3
+ // A spec may name Groundbox's own image ("default"), a template of the key's team, or another public image instead. Kind
4
+ // linux or desktop; the run's folder is a synced folder (derived); no Archil mount yet.
5
+ import { defineProvider } from "../descriptor.js";
6
+ import { LINUX_DESKTOP, SANDBOX } from "./shared.js";
7
+ /**
8
+ * The name of Groundbox's own image: no template and no image is sent, so Groundbox starts the team's default template
9
+ * when it has one, else its own image (Ubuntu 24.04 with the usual tools). Groundbox reserves the name, so no template
10
+ * can hold it. Not the provider's default: that image keeps toolchains under /opt deeper than the isolation probe
11
+ * searches, so the socket fence can't be proven on it.
12
+ */
13
+ export const GROUNDBOX_OWN_IMAGE = "default";
14
+ export const GROUNDBOX = defineProvider({
15
+ id: "groundbox",
16
+ label: "Groundbox",
17
+ keys: [{ name: "GROUNDBOX_API_KEY", option: "apiKey", required: true }],
18
+ metered: true,
19
+ // None yet: the guest kernel has FUSE, and Archil's client there is untried.
20
+ mounts: [],
21
+ // All three are ours: root in the guest makes a network namespace, so init's fence holds none and its egress proxy
22
+ // open and a list (hosted/network.ts). Groundbox's own allowlist (allow_hosts) is not used.
23
+ network: ["none", "open", "allow"],
24
+ // A linux computer, or a desktop (create()'s kind: "desktop"): the box image's Xvfb and xfwm4, started through computerd
25
+ // over the exec, as on E2B and boxd. Groundbox's own desktop (desktop: true, its own X server and Chrome) is not used.
26
+ capabilities: [SANDBOX, { ...LINUX_DESKTOP, options: { kind: "desktop" } }],
27
+ // No default image: every computer starts from the box image its prepareImage() answers, unless its spec names one.
28
+ prepareImage: true,
29
+ load: () => import("../groundbox.js"),
30
+ });
@@ -6,6 +6,7 @@ import { DAYTONA } from "./daytona.js";
6
6
  import { DOCKER } from "./docker.js";
7
7
  import { E2B } from "./e2b.js";
8
8
  import { FLY } from "./fly.js";
9
+ import { GROUNDBOX } from "./groundbox.js";
9
10
  import { KERNEL } from "./kernel.js";
10
11
  import { LOCAL } from "./local-chrome.js";
11
12
  import { MODAL } from "./modal.js";
@@ -59,6 +60,10 @@ export declare const DESCRIPTORS: readonly [{
59
60
  readonly name: "DAYTONA_ATTACH_EGRESS";
60
61
  readonly option: "attachEgress";
61
62
  readonly required: false;
63
+ }, {
64
+ readonly name: "DAYTONA_LISTED_MS";
65
+ readonly option: "listedMs";
66
+ readonly required: false;
62
67
  }];
63
68
  readonly settings: readonly [{
64
69
  readonly name: "daytonaConnect";
@@ -486,10 +491,37 @@ export declare const DESCRIPTORS: readonly [{
486
491
  readonly capabilities: readonly [import("../kinds.js").KindCapabilities];
487
492
  readonly prepareImage: true;
488
493
  readonly load: () => Promise<typeof import("../smolcloud.js")>;
494
+ }, {
495
+ readonly id: "groundbox";
496
+ readonly label: "Groundbox";
497
+ readonly keys: readonly [{
498
+ readonly name: "GROUNDBOX_API_KEY";
499
+ readonly option: "apiKey";
500
+ readonly required: true;
501
+ }];
502
+ readonly metered: true;
503
+ readonly mounts: readonly [];
504
+ readonly network: readonly ["none", "open", "allow"];
505
+ readonly capabilities: readonly [import("../kinds.js").KindCapabilities, {
506
+ readonly options: {
507
+ readonly kind: "desktop";
508
+ };
509
+ readonly kind: import("../protocol.js").ComputerKind;
510
+ readonly groups: import("../protocol.js").Group[];
511
+ readonly gpu?: import("../provider.js").GpuCapability;
512
+ readonly persistence?: {
513
+ keepsState: true;
514
+ resume: boolean;
515
+ };
516
+ readonly image?: string;
517
+ }];
518
+ readonly prepareImage: true;
519
+ readonly load: () => Promise<typeof import("../groundbox.js")>;
489
520
  }];
490
- export { AGENT37, BOXD, BROWSERBASE, CLOUDFLARE, DAYTONA, DOCKER, E2B, FLY, KERNEL, LOCAL, MODAL, MORPH, ORGO, PHONE_HARNESS, SMOLCLOUD };
521
+ export { AGENT37, BOXD, BROWSERBASE, CLOUDFLARE, DAYTONA, DOCKER, E2B, FLY, GROUNDBOX, KERNEL, LOCAL, MODAL, MORPH, ORGO, PHONE_HARNESS, SMOLCLOUD };
491
522
  export { AGENT37_BASE_TEMPLATE } from "./agent37.js";
492
523
  export { BOXD_DEFAULT_IMAGE } from "./boxd.js";
524
+ export { GROUNDBOX_OWN_IMAGE } from "./groundbox.js";
493
525
  export { DAYTONA_DEFAULT_SNAPSHOT, DAYTONA_GPU_SNAPSHOT, type DaytonaGpuSnapshot, daytonaGpu, daytonaGpuSnapshot } from "./daytona.js";
494
526
  export { ORGO_BASE_IMAGE } from "./orgo.js";
495
527
  export { PHONE_GROUPS, PHONE_IMAGE } from "./phone-harness.js";
@@ -8,6 +8,7 @@ import { DAYTONA } from "./daytona.js";
8
8
  import { DOCKER } from "./docker.js";
9
9
  import { E2B } from "./e2b.js";
10
10
  import { FLY } from "./fly.js";
11
+ import { GROUNDBOX } from "./groundbox.js";
11
12
  import { KERNEL } from "./kernel.js";
12
13
  import { LOCAL } from "./local-chrome.js";
13
14
  import { MODAL } from "./modal.js";
@@ -15,10 +16,11 @@ import { MORPH } from "./morph.js";
15
16
  import { ORGO } from "./orgo.js";
16
17
  import { PHONE_HARNESS } from "./phone-harness.js";
17
18
  import { SMOLCLOUD } from "./smolcloud.js";
18
- export const DESCRIPTORS = [DOCKER, DAYTONA, MODAL, E2B, AGENT37, MORPH, CLOUDFLARE, FLY, ORGO, PHONE_HARNESS, BROWSERBASE, KERNEL, LOCAL, BOXD, SMOLCLOUD];
19
- export { AGENT37, BOXD, BROWSERBASE, CLOUDFLARE, DAYTONA, DOCKER, E2B, FLY, KERNEL, LOCAL, MODAL, MORPH, ORGO, PHONE_HARNESS, SMOLCLOUD };
19
+ export const DESCRIPTORS = [DOCKER, DAYTONA, MODAL, E2B, AGENT37, MORPH, CLOUDFLARE, FLY, ORGO, PHONE_HARNESS, BROWSERBASE, KERNEL, LOCAL, BOXD, SMOLCLOUD, GROUNDBOX];
20
+ export { AGENT37, BOXD, BROWSERBASE, CLOUDFLARE, DAYTONA, DOCKER, E2B, FLY, GROUNDBOX, KERNEL, LOCAL, MODAL, MORPH, ORGO, PHONE_HARNESS, SMOLCLOUD };
20
21
  export { AGENT37_BASE_TEMPLATE } from "./agent37.js";
21
22
  export { BOXD_DEFAULT_IMAGE } from "./boxd.js";
23
+ export { GROUNDBOX_OWN_IMAGE } from "./groundbox.js";
22
24
  export { DAYTONA_DEFAULT_SNAPSHOT, DAYTONA_GPU_SNAPSHOT, daytonaGpu, daytonaGpuSnapshot } from "./daytona.js";
23
25
  export { ORGO_BASE_IMAGE } from "./orgo.js";
24
26
  export { PHONE_GROUPS, PHONE_IMAGE } from "./phone-harness.js";
package/dist/e2b.js CHANGED
@@ -4,7 +4,7 @@ import { DEADLINE_LABEL, show } from "./drift.js";
4
4
  import { installedProxy, proxyForDomain } from "./env-proxy.js";
5
5
  import { HostError } from "./host.js";
6
6
  import { deadlineOf, HostedProvider, isoOf, MAX_LABEL, timeoutsOf } from "./hosted/provider.js";
7
- import { AGENTRUN_DIAL, hostedCommands, shellLine } from "./hosted/scripts.js";
7
+ import { dialLaunch } from "./hosted/scripts.js";
8
8
  import { connectOf } from "./descriptor.js";
9
9
  import { dateOf, DOMAIN, isWhole, sizeRefusals } from "./hosted/values.js";
10
10
  import { PassThrough } from "node:stream";
@@ -75,16 +75,9 @@ const DIAL_LOG = "/run/agentrun-dial.log";
75
75
  /**
76
76
  * A dial machine's launch, root's command with boot env: E2B runs a template's start command once, at the template's
77
77
  * build, and snapshots it running, so it never sees a create's env (docs.e2b.dev/template/start-ready-command). So
78
- * create starts agentrun-dial itself, after the steps the exec path runs before init: ROOT_ONLY made root's alone, the
79
- * session buses in /tmp closed. A step that fails starts nothing, and the machine never dials.
78
+ * create starts agentrun-dial itself (dialLaunch), the URL in the boot env.
80
79
  */
81
- const DIAL_LAUNCH = [
82
- "-c",
83
- [
84
- `umask 077; exec >>${DIAL_LOG} 2>&1 </dev/null`,
85
- `${shellLine(hostedCommands({ rootOnly: ROOT_ONLY }).rootOnly)} && ${shellLine(hostedCommands().sockets)} && exec ${AGENTRUN_DIAL}`,
86
- ].join("\n"),
87
- ];
80
+ const DIAL_LAUNCH = ["-c", [`umask 077; exec >>${DIAL_LOG} 2>&1 </dev/null`, dialLaunch({ rootOnly: ROOT_ONLY })].join("\n")];
88
81
  /** The SDK names its errors (index.mjs:86-360); Connect's carry a code. */
89
82
  function codeOf(error) {
90
83
  const name = error?.name;
@@ -0,0 +1,61 @@
1
+ import { HostedProvider, type HostedOptions } from "./hosted/provider.js";
2
+ import { type Result } from "./result.js";
3
+ /** The parts of a WebSocket the host uses: Node's global WebSocket, or a stand-in in tests. */
4
+ export interface GroundboxSocket {
5
+ /** 0 connecting, 1 open, 2 closing, 3 closed. */
6
+ readonly readyState: number;
7
+ /** Bytes sent and not yet on the wire: a write waits while it is high. */
8
+ readonly bufferedAmount: number;
9
+ send(text: string): void;
10
+ close(code?: number): void;
11
+ addEventListener(type: "open" | "message" | "close" | "error", listener: (event: {
12
+ data?: unknown;
13
+ code?: number;
14
+ message?: string;
15
+ }) => void): void;
16
+ }
17
+ export type GroundboxSocketFactory = (url: string, init: {
18
+ headers: Record<string, string>;
19
+ }) => GroundboxSocket;
20
+ /** The Groundbox provider's options: the key and Groundbox's own settings, then the shared adapter's (HostedOptions). */
21
+ export interface GroundboxProviderOptions extends HostedOptions {
22
+ /** The Groundbox API key (gbx_...). The caller passes it; this provider never reads it from the environment. */
23
+ apiKey: string;
24
+ /** The REST API, ending in /v1; default https://api.groundbox.dev/v1. */
25
+ apiUrl?: string;
26
+ /** Every sandbox's disk, in whole GB, 1 to 100; default Groundbox's own (20). A spec names no disk. */
27
+ diskGb?: number;
28
+ /** The fetch every call goes through; default the global one. */
29
+ fetch?: typeof fetch;
30
+ /** For tests: every command stream opens through it. Default Node's global WebSocket. */
31
+ webSocket?: GroundboxSocketFactory;
32
+ /**
33
+ * For tests: the command stream's bounds (the silence after which a socket is taken as dead; the unread output that
34
+ * pauses reading, and the level it resumes at).
35
+ */
36
+ streamBounds?: Partial<StreamBounds>;
37
+ }
38
+ export declare function create(options: GroundboxProviderOptions): Promise<GroundboxProvider>;
39
+ /** The conformance CLI's module for Groundbox: its live switch, the run's 30-minute cap and its image. */
40
+ export declare const conformance: () => Promise<typeof import("./conformance/groundbox.js")>;
41
+ /** The command stream's bounds: SILENCE_MS, QUEUE_HIGH, QUEUE_LOW and RESUME_GIVE_UP_MS unless a test gives others. */
42
+ export interface StreamBounds {
43
+ silenceMs: number;
44
+ queueHighBytes: number;
45
+ queueLowBytes: number;
46
+ resumeGiveUpMs: number;
47
+ }
48
+ /**
49
+ * Computers that are Groundbox sandboxes, on the shared adapter. A spec's image is the box image by default
50
+ * (prepareImage), "default" (the team's default template, else Groundbox's own image), a template of the key's team, or
51
+ * a public image.
52
+ */
53
+ export declare class GroundboxProvider extends HostedProvider {
54
+ /**
55
+ * The provider contract's prepareImage (its descriptor declares it): the box image the release publishes, by its
56
+ * public registry tag (box-image.ts). No call: Groundbox turns it into a disk at the first create from it, and keeps
57
+ * that disk for later ones.
58
+ */
59
+ prepareImage(): Promise<Result<string>>;
60
+ constructor(options: GroundboxProviderOptions);
61
+ }