@parcha/agentrun-computer 0.1.0-beta.57 → 0.1.0-beta.59

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 (131) hide show
  1. package/README.md +187 -62
  2. package/box/Dockerfile +4 -3
  3. package/box/install.sh +57 -11
  4. package/dist/agent37.js +6 -9
  5. package/dist/attach.d.ts +24 -4
  6. package/dist/attach.js +50 -19
  7. package/dist/boxd.js +22 -9
  8. package/dist/browserbase.d.ts +6 -2
  9. package/dist/browserbase.js +50 -7
  10. package/dist/child-env.d.ts +11 -0
  11. package/dist/child-env.js +22 -0
  12. package/dist/chrome.d.ts +5 -2
  13. package/dist/chrome.js +5 -2
  14. package/dist/cloudflare.d.ts +2 -0
  15. package/dist/cloudflare.js +5 -3
  16. package/dist/computerd-linux-amd64 +0 -0
  17. package/dist/computerd-linux-arm64 +0 -0
  18. package/dist/computerd.json +1 -1
  19. package/dist/conformance/agent37.d.ts +10 -38
  20. package/dist/conformance/agent37.js +25 -113
  21. package/dist/conformance/archil.d.ts +13 -3
  22. package/dist/conformance/archil.js +22 -17
  23. package/dist/conformance/boxd.d.ts +8 -31
  24. package/dist/conformance/boxd.js +19 -74
  25. package/dist/conformance/browserbase.d.ts +3 -6
  26. package/dist/conformance/browserbase.js +6 -17
  27. package/dist/conformance/cases/health.js +6 -3
  28. package/dist/conformance/cli.d.ts +3 -1
  29. package/dist/conformance/cli.js +69 -9
  30. package/dist/conformance/cloudflare.d.ts +3 -6
  31. package/dist/conformance/cloudflare.js +7 -15
  32. package/dist/conformance/daytona.d.ts +6 -20
  33. package/dist/conformance/daytona.js +22 -57
  34. package/dist/conformance/dial-only.d.ts +4 -3
  35. package/dist/conformance/dial-only.js +3 -3
  36. package/dist/conformance/docker.d.ts +4 -5
  37. package/dist/conformance/docker.js +8 -14
  38. package/dist/conformance/e2b.d.ts +10 -36
  39. package/dist/conformance/e2b.js +27 -84
  40. package/dist/conformance/fly.d.ts +3 -6
  41. package/dist/conformance/fly.js +2 -6
  42. package/dist/conformance/groundbox.d.ts +7 -23
  43. package/dist/conformance/groundbox.js +16 -56
  44. package/dist/conformance/index.d.ts +1 -0
  45. package/dist/conformance/index.js +1 -0
  46. package/dist/conformance/kernel.d.ts +3 -6
  47. package/dist/conformance/kernel.js +5 -15
  48. package/dist/conformance/kind.d.ts +0 -6
  49. package/dist/conformance/kind.js +0 -4
  50. package/dist/conformance/local-chrome.d.ts +5 -7
  51. package/dist/conformance/local-chrome.js +7 -11
  52. package/dist/conformance/modal.d.ts +10 -38
  53. package/dist/conformance/modal.js +27 -74
  54. package/dist/conformance/module-kit.d.ts +87 -0
  55. package/dist/conformance/module-kit.js +88 -0
  56. package/dist/conformance/morph.d.ts +7 -23
  57. package/dist/conformance/morph.js +20 -66
  58. package/dist/conformance/orgo.d.ts +5 -10
  59. package/dist/conformance/orgo.js +15 -27
  60. package/dist/conformance/phone-harness.d.ts +3 -5
  61. package/dist/conformance/phone-harness.js +3 -11
  62. package/dist/conformance/runner.d.ts +13 -3
  63. package/dist/conformance/runner.js +32 -11
  64. package/dist/conformance/smolcloud.d.ts +7 -23
  65. package/dist/conformance/smolcloud.js +16 -49
  66. package/dist/conformance/sweep.d.ts +10 -5
  67. package/dist/conformance/sweep.js +91 -38
  68. package/dist/conformance/tti.d.ts +69 -0
  69. package/dist/conformance/tti.js +205 -0
  70. package/dist/conformance/types.d.ts +9 -2
  71. package/dist/daytona.js +60 -20
  72. package/dist/descriptor.d.ts +10 -0
  73. package/dist/descriptor.js +7 -0
  74. package/dist/descriptors/browserbase.d.ts +3 -0
  75. package/dist/descriptors/browserbase.js +4 -0
  76. package/dist/descriptors/docker.d.ts +1 -0
  77. package/dist/descriptors/docker.js +3 -0
  78. package/dist/descriptors/env-names.d.ts +32 -0
  79. package/dist/descriptors/env-names.js +60 -0
  80. package/dist/descriptors/index.d.ts +9 -2
  81. package/dist/descriptors/kernel.d.ts +3 -0
  82. package/dist/descriptors/kernel.js +2 -0
  83. package/dist/descriptors/local-chrome.d.ts +1 -1
  84. package/dist/descriptors/local-chrome.js +5 -3
  85. package/dist/descriptors/phone-harness.d.ts +1 -1
  86. package/dist/descriptors/phone-harness.js +4 -2
  87. package/dist/docker/egress.d.ts +7 -0
  88. package/dist/docker/egress.js +8 -0
  89. package/dist/docker/image.d.ts +5 -1
  90. package/dist/docker/image.js +12 -8
  91. package/dist/docker.d.ts +63 -15
  92. package/dist/docker.js +181 -98
  93. package/dist/drift.js +6 -6
  94. package/dist/e2b.d.ts +2 -2
  95. package/dist/e2b.js +2 -3
  96. package/dist/groundbox.js +6 -6
  97. package/dist/host.d.ts +23 -0
  98. package/dist/hosted/download.d.ts +23 -0
  99. package/dist/hosted/download.js +144 -0
  100. package/dist/hosted/process.d.ts +5 -0
  101. package/dist/hosted/process.js +20 -0
  102. package/dist/hosted/provider.js +120 -48
  103. package/dist/hosted/rest.d.ts +19 -8
  104. package/dist/hosted/rest.js +47 -14
  105. package/dist/hosted/scripts.d.ts +10 -0
  106. package/dist/hosted/scripts.js +23 -2
  107. package/dist/index.d.ts +3 -1
  108. package/dist/index.js +3 -1
  109. package/dist/janitor.d.ts +7 -1
  110. package/dist/janitor.js +2 -2
  111. package/dist/kernel.js +1 -1
  112. package/dist/local-chrome.d.ts +5 -2
  113. package/dist/local-chrome.js +4 -2
  114. package/dist/local-supervisor.js +1 -0
  115. package/dist/modal.d.ts +6 -5
  116. package/dist/modal.js +7 -7
  117. package/dist/morph.js +5 -8
  118. package/dist/orgo-channel.d.ts +3 -2
  119. package/dist/orgo-channel.js +3 -3
  120. package/dist/orgo-desktop.js +2 -4
  121. package/dist/orgo.js +2 -4
  122. package/dist/phone-harness.d.ts +7 -5
  123. package/dist/phone-harness.js +60 -61
  124. package/dist/protocol.d.ts +10 -0
  125. package/dist/protocol.js +17 -0
  126. package/dist/provider.d.ts +6 -2
  127. package/dist/screen-watch.d.ts +6 -1
  128. package/dist/screen-watch.js +166 -12
  129. package/dist/vendor-sdk.d.ts +9 -0
  130. package/dist/vendor-sdk.js +26 -0
  131. package/package.json +8 -1
package/dist/daytona.js CHANGED
@@ -71,7 +71,10 @@ const OUT = Buffer.from([1, 1, 1]);
71
71
  const ERR = Buffer.from([2, 2, 2]);
72
72
  /** A line the client wrote, echoed back: a request or a notification is never a daemon's reply. */
73
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. */
74
+ /**
75
+ * The toolbox session a dial sandbox's agentrun-dial runs in, its one command: dialLog reads its log by this id. A
76
+ * second start (redial) runs in a session of its own, this name with -2.
77
+ */
75
78
  const DIAL_SESSION = "agentrun-dial";
76
79
  const decoder = new TextDecoder();
77
80
  /**
@@ -127,12 +130,18 @@ class DaytonaHost {
127
130
  */
128
131
  descriptor = DAYTONA;
129
132
  facts;
130
- /** connect exec alone: a dial host has neither (HostFacts.connect). */
133
+ /** connect exec alone: a dial host has none of them (HostFacts.connect). */
131
134
  exec;
132
135
  upload;
133
- /** connect dial alone: agentrun-dial's session command's log. */
136
+ download;
137
+ /** connect dial alone: agentrun-dial's session command's log, its exit, and its second start. */
134
138
  dialLog;
135
- /** The command that runs agentrun-dial, by sandbox id, from its create: what dialLog reads. Let go of at its delete. */
139
+ dialExit;
140
+ redial;
141
+ /**
142
+ * The session and command that run agentrun-dial, by sandbox id, from its create or its second start, and the attach
143
+ * URL its line sets: what dialLog and dialExit read, and redial starts again. Let go of at its delete.
144
+ */
136
145
  #dials = new Map();
137
146
  /** Daytona's REST API: the control plane, and the toolbox of each sandbox. */
138
147
  #rest;
@@ -178,9 +187,13 @@ class DaytonaHost {
178
187
  if (options.connect === "exec") {
179
188
  this.exec = (id, argv, ctx) => this.#exec(id, argv, ctx);
180
189
  this.upload = (id, path, bytes, ctx) => this.#upload(id, path, bytes, ctx);
190
+ this.download = (id, path, ctx) => this.#download(id, path, ctx);
181
191
  }
182
- else
192
+ else {
183
193
  this.dialLog = (id, ctx) => this.#dialLog(id, ctx);
194
+ this.dialExit = (id, ctx) => this.#dialExit(id, ctx);
195
+ this.redial = (id, ctx) => this.#redial(id, ctx);
196
+ }
184
197
  }
185
198
  /**
186
199
  * A snapshot name has no control characters, and its size is the snapshot's; a GPU computer is made from the
@@ -292,7 +305,7 @@ class DaytonaHost {
292
305
  try {
293
306
  const toolbox = await this.#toolbox(id);
294
307
  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);
308
+ this.#dials.set(id, { session: DIAL_SESSION, command: commandId, attach, starts: 1 });
296
309
  }
297
310
  catch (error) {
298
311
  throw new HostError("vendor", `starting agentrun-dial in ${id} failed: ${words(error)}`);
@@ -304,13 +317,39 @@ class DaytonaHost {
304
317
  * prefixes are dropped. undefined when this host started no agentrun-dial there.
305
318
  */
306
319
  async #dialLog(id, ctx) {
307
- const commandId = this.#dials.get(id);
308
- if (commandId === undefined)
320
+ const dial = this.#dials.get(id);
321
+ if (dial === undefined)
309
322
  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));
323
+ const session = `${await this.#toolbox(id, ctx.signal)}/process/session/${dial.session}`;
324
+ const logs = orThrow(await this.#rest.call("GET", `${session}/command/${encodeURIComponent(dial.command)}/logs`, { retry: true, timeoutMs: ctx.timeoutMs }, ctx.signal));
312
325
  return decoder.decode(logs.bytes).replaceAll(OUT.toString("latin1"), "").replaceAll(ERR.toString("latin1"), "");
313
326
  }
327
+ /**
328
+ * agentrun-dial's exit code: one read of its session, whose command of the id its start returned carries exitCode
329
+ * once it has exited (as the exec path reads a command's exit). undefined while it runs, and where this host started
330
+ * no agentrun-dial.
331
+ */
332
+ async #dialExit(id, ctx) {
333
+ const dial = this.#dials.get(id);
334
+ if (dial === undefined)
335
+ return undefined;
336
+ const read = orThrow(await this.#rest.json("GET", `${await this.#toolbox(id, ctx.signal)}/process/session/${dial.session}`, { retry: true, timeoutMs: ctx.timeoutMs }, ctx.signal));
337
+ const found = (read?.commands ?? []).find((one) => one.id === dial.command);
338
+ return typeof found?.exitCode === "number" ? found.exitCode : undefined;
339
+ }
340
+ /**
341
+ * agentrun-dial started once more, as create started it (dialLaunch's line, the same attach URL; the token is the
342
+ * sandbox's env still), in a session of its own: dialLog and dialExit read that one from then. A sandbox this host
343
+ * started no agentrun-dial in is refused.
344
+ */
345
+ async #redial(id, ctx) {
346
+ const dial = this.#dials.get(id);
347
+ if (dial === undefined)
348
+ throw new HostError("not_found", `no agentrun-dial was started in the sandbox ${id}, so it is not started again`);
349
+ const session = `${DIAL_SESSION}-${dial.starts + 1}`;
350
+ const { commandId } = await this.#runAsync(await this.#toolbox(id, ctx.signal), session, dialLaunch({ rootOnly: this.facts.rootOnly, attach: dial.attach }), ctx.timeoutMs, ctx.signal);
351
+ this.#dials.set(id, { ...dial, session, command: commandId, starts: dial.starts + 1 });
352
+ }
314
353
  /** GET /sandbox/{id}; one Daytona answers 404 for, or reads destroyed, is none. */
315
354
  async get(id, ctx) {
316
355
  const found = orThrow(await sandboxOf(this.#rest, id, ctx.signal));
@@ -380,16 +419,7 @@ class DaytonaHost {
380
419
  const asked = orThrow(await this.#rest.json("GET", sandboxUrl(this.#rest, id, "/toolbox-proxy-url"), { retry: true }, signal));
381
420
  proxy = asked?.url;
382
421
  }
383
- let url;
384
- try {
385
- url = new URL(proxy ?? "");
386
- }
387
- catch {
388
- throw new Error(`Daytona gave no toolbox URL for ${id}`);
389
- }
390
- if (url.protocol !== "https:")
391
- throw new Error(`the toolbox URL Daytona gave is not https (${url.protocol}), so the key is not sent to it`);
392
- const toolbox = `${url.href.replace(/\/+$/, "")}/${encodeURIComponent(id)}`;
422
+ const toolbox = `${httpsBase(proxy ?? "", `the toolbox URL Daytona gave for ${id}`)}/${encodeURIComponent(id)}`;
393
423
  this.#toolboxes.set(id, toolbox);
394
424
  return toolbox;
395
425
  }
@@ -415,6 +445,16 @@ class DaytonaHost {
415
445
  if (!older.ok)
416
446
  throw new HostError(older.error.code, `${missing}, then ${older.error.message}`);
417
447
  }
448
+ /**
449
+ * The bytes of the file at `path` in the sandbox, whole: the toolbox's GET files/download (the open daemon's routes,
450
+ * daytonaio/daytona@b5a5d9e7 apps/daemon/pkg/toolbox/server.go), as root. Far faster than exec's stdout, which is a
451
+ * session command's log read over a WebSocket (about 0.3 MB/s, the sandbox bench, 11-25). Connect exec alone.
452
+ */
453
+ async #download(id, path, ctx) {
454
+ const toolbox = await this.#toolbox(id, ctx.signal);
455
+ const got = orThrow(await this.#rest.call("GET", `${toolbox}/files/download?${new URLSearchParams({ path })}`, { retry: true, timeoutMs: ctx.timeoutMs }, ctx.signal));
456
+ return got.bytes;
457
+ }
418
458
  /**
419
459
  * A session command of its own (#commands), on framedExec: argv as one shell line, run async with no input echo, as
420
460
  * the toolbox's user (root, or one with passwordless sudo, which the adapter's scripts use). Connect exec alone.
@@ -145,6 +145,16 @@ export interface ProviderDescriptor<Module extends ProviderModule = ProviderModu
145
145
  * image. No setting kind lists one, and Settings never offers one.
146
146
  */
147
147
  readonly parked?: readonly ParkedConfiguration[];
148
+ /**
149
+ * Its browsers open a profile the vendor keeps (a Browserbase context, a Kernel profile), which its built providers
150
+ * make and delete (profiles.create, profiles.remove) and declare (capabilities().browser.profiles, this same value). A
151
+ * server keeps an agent's saved sign-in only at a provider that declares this. settleMs: how long after a saving
152
+ * session ends the vendor may still be writing the profile back, which a server waits out before another session saves
153
+ * to it. Absent: its browsers keep no profile.
154
+ */
155
+ readonly profiles?: {
156
+ readonly settleMs: number;
157
+ };
148
158
  /** The provider module, loaded on demand: its create(), its conformance module. */
149
159
  load(): Promise<Module>;
150
160
  }
@@ -114,6 +114,13 @@ export function descriptorProblems(value) {
114
114
  else if (Array.isArray(d.capabilities) && d.parked.some((one) => d.capabilities.some((offered) => offered?.image === one.image)))
115
115
  problems.push("a parked image is also offered");
116
116
  }
117
+ if (d.profiles !== undefined) {
118
+ const settleMs = d.profiles?.settleMs;
119
+ if (typeof settleMs !== "number" || !Number.isInteger(settleMs) || settleMs < 0)
120
+ problems.push("profiles is { settleMs }, a whole number of milliseconds, 0 or more");
121
+ else if (!Array.isArray(d.capabilities) || !d.capabilities.some((one) => one?.kind === "browser"))
122
+ problems.push("profiles is a browser's: no configuration is of kind browser");
123
+ }
117
124
  return problems;
118
125
  }
119
126
  /**
@@ -21,5 +21,8 @@ export declare const BROWSERBASE: {
21
21
  readonly defaultImage: {
22
22
  readonly browser: "chromium";
23
23
  };
24
+ readonly profiles: {
25
+ readonly settleMs: 10000;
26
+ };
24
27
  readonly load: () => Promise<typeof import("../browserbase.js")>;
25
28
  };
@@ -16,5 +16,9 @@ export const BROWSERBASE = defineProvider({
16
16
  hostEnv: ["BROWSERBASE_BASE_URL", "BROWSERBASE_CONNECT_BASE_URL"],
17
17
  capabilities: [{ kind: "browser", groups: ["cdp", "stream"] }],
18
18
  defaultImage: { browser: BROWSER_IMAGE },
19
+ // A profile is a context, which Browserbase writes back a few seconds after a saving session ends and publishes no
20
+ // bound for: 10 s, twice the few seconds seen, since a session opened on it too soon starts from what was there
21
+ // before, and a wait too long only holds the next save back.
22
+ profiles: { settleMs: 10_000 },
19
23
  load: () => import("../browserbase.js"),
20
24
  });
@@ -20,5 +20,6 @@ export declare const DOCKER: {
20
20
  }];
21
21
  readonly prepareImage: true;
22
22
  readonly local: true;
23
+ readonly hostEnv: readonly string[];
23
24
  readonly load: () => Promise<typeof import("../docker.js")>;
24
25
  };
@@ -1,4 +1,5 @@
1
1
  // Docker's descriptor: computers on this machine's Docker, a sandbox or a desktop; no key, no meter.
2
+ import { DOCKER_ENV_NAMES } from "./env-names.js";
2
3
  import { defineProvider } from "../descriptor.js";
3
4
  import { LINUX_DESKTOP, SANDBOX } from "./shared.js";
4
5
  export const DOCKER = defineProvider({
@@ -15,5 +16,7 @@ export const DOCKER = defineProvider({
15
16
  // No default image: the server makes one from the provider's recipe (prepareImage) before the first create.
16
17
  prepareImage: true,
17
18
  local: true,
19
+ // What the docker CLI reads (env-names.ts DOCKER_ENV_NAMES): the server's own values of these, and no other.
20
+ hostEnv: DOCKER_ENV_NAMES,
18
21
  load: () => import("../docker.js"),
19
22
  });
@@ -0,0 +1,32 @@
1
+ /** The variables every child reads: where programs and the home and temp directories are, the locale, and Windows' and
2
+ * macOS's own. */
3
+ export declare const BASE_ENV_NAMES: readonly string[];
4
+ /**
5
+ * The docker CLI's, beside the base (and what it starts: buildx, ssh, a credential helper, which inherit its environment):
6
+ * - the daemon: DOCKER_HOST, DOCKER_CONTEXT, the TLS files, the API version; SSH_AUTH_SOCK for an ssh:// host;
7
+ * - content trust: DOCKER_CONTENT_TRUST and its server, so a host that verifies its images' signatures still does;
8
+ * XDG_RUNTIME_DIR for a rootless one; the proxy a TCP daemon or a registry is reached through, in both cases;
9
+ * - its config: DOCKER_CONFIG, else HOME's .docker (config.json, contexts, cli-plugins, buildx), BUILDX_*;
10
+ * - a pull's credentials: the credential helper config.json names (docker-credential-<name>, on PATH) finds them where
11
+ * these say: the Secret Service's bus, GnuPG's home and agent, a cloud CLI's profile, region and config. Never a key
12
+ * (AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN, AZURE_CLIENT_SECRET, DOCKER_CUSTOM_HEADERS, a content trust passphrase),
13
+ * nor a name shaped as one (AWS_SHARED_CREDENTIALS_FILE, AWS_WEB_IDENTITY_TOKEN_FILE,
14
+ * AWS_CONTAINER_CREDENTIALS_RELATIVE_URI, GOOGLE_APPLICATION_CREDENTIALS, PASSWORD_STORE_DIR): a helper that needs
15
+ * one reads it from its default place, a profile or a role instead.
16
+ */
17
+ export declare const DOCKER_ENV_NAMES: readonly string[];
18
+ /**
19
+ * Chrome's, beside the base, for the local browser's supervisor and the Chrome it starts and the sandbox check's Chrome:
20
+ * the display it may draw on (X's or Wayland's, and X's authority file), the XDG directories it keeps its config, cache
21
+ * and fonts' cache in, fontconfig's files, the session bus, and the setuid sandbox's path where a host names one. No
22
+ * proxy: Chrome is always given its own (--proxy-server), the fence. Nothing else it may read (GOOGLE_API_KEY and the
23
+ * like, Google's services' keys) reaches it.
24
+ */
25
+ export declare const CHROME_ENV_NAMES: readonly string[];
26
+ /**
27
+ * adb's (Android platform-tools), beside the base, for every adb the phone provider runs and the adb server it starts:
28
+ * where the SDK is (ANDROID_HOME, ANDROID_SDK_ROOT) and where adb keeps its key pair (ANDROID_USER_HOME, or the older
29
+ * ANDROID_SDK_HOME). No ADB_* nor ANDROID_ADB_* name and no ANDROID_SERIAL: each points adb at another server or
30
+ * device than the provider's own -P port and socket requests reach.
31
+ */
32
+ export declare const ADB_ENV_NAMES: readonly string[];
@@ -0,0 +1,60 @@
1
+ // The names of the host's environment a child this package starts is handed (child-env.ts childEnv): every child's,
2
+ // the docker CLI's, Chrome's and adb's. Here, beside the descriptors, so a descriptor's hostEnv names them and loads no provider
3
+ // code; this file imports nothing.
4
+ //
5
+ // No list names a variable serve's keyShaped() takes for a key's (a segment KEY, TOKEN, SECRET, PASS, CREDENTIAL(S) ...):
6
+ // serve's child-env-names test holds that for every list here. Docker's own credential places stay (DOCKER_CONFIG, a
7
+ // cloud CLI's config file, GnuPG's home), since a pull reads its registry's credentials there.
8
+ /** The variables every child reads: where programs and the home and temp directories are, the locale, and Windows' and
9
+ * macOS's own. */
10
+ export const BASE_ENV_NAMES = Object.freeze([
11
+ "PATH", "HOME", "TMPDIR", "TZ",
12
+ "LANG", "LANGUAGE", "LC_ALL", "LC_CTYPE", "LC_COLLATE", "LC_MESSAGES", "LC_NUMERIC", "LC_TIME", "LC_MONETARY", "LC_PAPER",
13
+ "LC_NAME", "LC_ADDRESS", "LC_TELEPHONE", "LC_MEASUREMENT", "LC_IDENTIFICATION",
14
+ "SystemRoot", "SYSTEMROOT", "WINDIR", "USERPROFILE", "APPDATA", "LOCALAPPDATA", "ProgramData", "PATHEXT", "COMSPEC", "TEMP", "TMP",
15
+ ]);
16
+ /**
17
+ * The docker CLI's, beside the base (and what it starts: buildx, ssh, a credential helper, which inherit its environment):
18
+ * - the daemon: DOCKER_HOST, DOCKER_CONTEXT, the TLS files, the API version; SSH_AUTH_SOCK for an ssh:// host;
19
+ * - content trust: DOCKER_CONTENT_TRUST and its server, so a host that verifies its images' signatures still does;
20
+ * XDG_RUNTIME_DIR for a rootless one; the proxy a TCP daemon or a registry is reached through, in both cases;
21
+ * - its config: DOCKER_CONFIG, else HOME's .docker (config.json, contexts, cli-plugins, buildx), BUILDX_*;
22
+ * - a pull's credentials: the credential helper config.json names (docker-credential-<name>, on PATH) finds them where
23
+ * these say: the Secret Service's bus, GnuPG's home and agent, a cloud CLI's profile, region and config. Never a key
24
+ * (AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN, AZURE_CLIENT_SECRET, DOCKER_CUSTOM_HEADERS, a content trust passphrase),
25
+ * nor a name shaped as one (AWS_SHARED_CREDENTIALS_FILE, AWS_WEB_IDENTITY_TOKEN_FILE,
26
+ * AWS_CONTAINER_CREDENTIALS_RELATIVE_URI, GOOGLE_APPLICATION_CREDENTIALS, PASSWORD_STORE_DIR): a helper that needs
27
+ * one reads it from its default place, a profile or a role instead.
28
+ */
29
+ export const DOCKER_ENV_NAMES = Object.freeze([
30
+ ...BASE_ENV_NAMES,
31
+ "DOCKER_HOST", "DOCKER_CONTEXT", "DOCKER_CONFIG", "DOCKER_CERT_PATH", "DOCKER_TLS", "DOCKER_TLS_VERIFY", "DOCKER_API_VERSION",
32
+ "DOCKER_CONTENT_TRUST", "DOCKER_CONTENT_TRUST_SERVER",
33
+ "DOCKER_DEFAULT_PLATFORM", "DOCKER_BUILDKIT", "BUILDX_CONFIG", "BUILDX_BUILDER",
34
+ "SSH_AUTH_SOCK", "XDG_RUNTIME_DIR", "XDG_CONFIG_HOME",
35
+ "HTTP_PROXY", "HTTPS_PROXY", "NO_PROXY", "ALL_PROXY", "http_proxy", "https_proxy", "no_proxy", "all_proxy",
36
+ "DBUS_SESSION_BUS_ADDRESS", "GNUPGHOME", "GPG_AGENT_INFO",
37
+ "AWS_PROFILE", "AWS_REGION", "AWS_DEFAULT_REGION", "AWS_CONFIG_FILE", "AWS_SDK_LOAD_CONFIG",
38
+ "CLOUDSDK_CONFIG",
39
+ ]);
40
+ /**
41
+ * Chrome's, beside the base, for the local browser's supervisor and the Chrome it starts and the sandbox check's Chrome:
42
+ * the display it may draw on (X's or Wayland's, and X's authority file), the XDG directories it keeps its config, cache
43
+ * and fonts' cache in, fontconfig's files, the session bus, and the setuid sandbox's path where a host names one. No
44
+ * proxy: Chrome is always given its own (--proxy-server), the fence. Nothing else it may read (GOOGLE_API_KEY and the
45
+ * like, Google's services' keys) reaches it.
46
+ */
47
+ export const CHROME_ENV_NAMES = Object.freeze([
48
+ ...BASE_ENV_NAMES,
49
+ "DISPLAY", "WAYLAND_DISPLAY", "XAUTHORITY",
50
+ "XDG_RUNTIME_DIR", "XDG_CONFIG_HOME", "XDG_CACHE_HOME", "XDG_DATA_HOME", "XDG_DATA_DIRS", "XDG_CONFIG_DIRS",
51
+ "FONTCONFIG_FILE", "FONTCONFIG_PATH", "FONTCONFIG_SYSROOT",
52
+ "DBUS_SESSION_BUS_ADDRESS", "CHROME_DEVEL_SANDBOX",
53
+ ]);
54
+ /**
55
+ * adb's (Android platform-tools), beside the base, for every adb the phone provider runs and the adb server it starts:
56
+ * where the SDK is (ANDROID_HOME, ANDROID_SDK_ROOT) and where adb keeps its key pair (ANDROID_USER_HOME, or the older
57
+ * ANDROID_SDK_HOME). No ADB_* nor ANDROID_ADB_* name and no ANDROID_SERIAL: each points adb at another server or
58
+ * device than the provider's own -P port and socket requests reach.
59
+ */
60
+ export const ADB_ENV_NAMES = Object.freeze([...BASE_ENV_NAMES, "ANDROID_HOME", "ANDROID_SDK_ROOT", "ANDROID_USER_HOME", "ANDROID_SDK_HOME"]);
@@ -36,6 +36,7 @@ export declare const DESCRIPTORS: readonly [{
36
36
  }];
37
37
  readonly prepareImage: true;
38
38
  readonly local: true;
39
+ readonly hostEnv: readonly string[];
39
40
  readonly load: () => Promise<typeof import("../docker.js")>;
40
41
  }, {
41
42
  readonly id: "daytona";
@@ -363,7 +364,7 @@ export declare const DESCRIPTORS: readonly [{
363
364
  readonly from: "Android platform-tools";
364
365
  readonly builds: readonly ["linux-x64", "darwin-x64", "darwin-arm64", "win32-x64"];
365
366
  };
366
- readonly hostEnv: readonly ["PHONE_HARNESS_APKS"];
367
+ readonly hostEnv: readonly ["PHONE_HARNESS_APKS", ...string[]];
367
368
  readonly load: () => Promise<typeof import("../phone-harness.js")>;
368
369
  }, {
369
370
  readonly id: "browserbase";
@@ -388,6 +389,9 @@ export declare const DESCRIPTORS: readonly [{
388
389
  readonly defaultImage: {
389
390
  readonly browser: "chromium";
390
391
  };
392
+ readonly profiles: {
393
+ readonly settleMs: 10000;
394
+ };
391
395
  readonly load: () => Promise<typeof import("../browserbase.js")>;
392
396
  }, {
393
397
  readonly id: "kernel";
@@ -408,6 +412,9 @@ export declare const DESCRIPTORS: readonly [{
408
412
  readonly defaultImage: {
409
413
  readonly browser: "chromium";
410
414
  };
415
+ readonly profiles: {
416
+ readonly settleMs: 0;
417
+ };
411
418
  readonly load: () => Promise<typeof import("../kernel.js")>;
412
419
  }, {
413
420
  readonly id: "local-chrome";
@@ -423,7 +430,7 @@ export declare const DESCRIPTORS: readonly [{
423
430
  readonly defaultImage: {
424
431
  readonly browser: "chromium";
425
432
  };
426
- readonly hostEnv: readonly ["PI_BROWSER_CHROME", "CHROME_PATH", "PATH"];
433
+ readonly hostEnv: readonly ["PI_BROWSER_CHROME", "CHROME_PATH", ...string[]];
427
434
  readonly load: () => Promise<typeof import("../local-chrome.js")>;
428
435
  }, {
429
436
  readonly id: "boxd";
@@ -17,5 +17,8 @@ export declare const KERNEL: {
17
17
  readonly defaultImage: {
18
18
  readonly browser: "chromium";
19
19
  };
20
+ readonly profiles: {
21
+ readonly settleMs: 0;
22
+ };
20
23
  readonly load: () => Promise<typeof import("../kernel.js")>;
21
24
  };
@@ -13,5 +13,7 @@ export const KERNEL = defineProvider({
13
13
  hostEnv: ["KERNEL_BASE_URL"],
14
14
  capabilities: [{ kind: "browser", groups: ["cdp", "stream"] }],
15
15
  defaultImage: { browser: BROWSER_IMAGE },
16
+ // A profile Kernel has written back once the browser that saved to it is deleted: nothing to wait out.
17
+ profiles: { settleMs: 0 },
16
18
  load: () => import("../kernel.js"),
17
19
  });
@@ -12,6 +12,6 @@ export declare const LOCAL: {
12
12
  readonly defaultImage: {
13
13
  readonly browser: "chromium";
14
14
  };
15
- readonly hostEnv: readonly ["PI_BROWSER_CHROME", "CHROME_PATH", "PATH"];
15
+ readonly hostEnv: readonly ["PI_BROWSER_CHROME", "CHROME_PATH", ...string[]];
16
16
  readonly load: () => Promise<typeof import("../local-chrome.js")>;
17
17
  };
@@ -2,6 +2,7 @@
2
2
  // addresses through its egress proxy, every one or only a list's. No live view: a person watching runs it headed. Its id is local-chrome, a token
3
3
  // nothing else in the code base uses (a folder mode, a region and an API tag are all "local").
4
4
  import { defineProvider } from "../descriptor.js";
5
+ import { CHROME_ENV_NAMES } from "./env-names.js";
5
6
  import { BROWSER_IMAGE } from "./shared.js";
6
7
  export const LOCAL = defineProvider({
7
8
  id: "local-chrome",
@@ -14,8 +15,9 @@ export const LOCAL = defineProvider({
14
15
  network: ["open", "allow"],
15
16
  capabilities: [{ kind: "browser", groups: ["cdp"] }],
16
17
  defaultImage: { browser: BROWSER_IMAGE },
17
- // Where it finds this machine's Chrome (chrome.ts CHROME_ENV, then PATH): the server's own values of these, and no
18
- // other. Written out, so reading the descriptor loads no provider code (kinds.test holds the two lists together).
19
- hostEnv: ["PI_BROWSER_CHROME", "CHROME_PATH", "PATH"],
18
+ // Where it finds this machine's Chrome (chrome.ts CHROME_ENV, then PATH), and what Chrome reads (env-names.ts
19
+ // CHROME_ENV_NAMES): the server's own values of these, and no other. The finder's two are written out, so reading the
20
+ // descriptor loads no provider code (kinds.test holds the lists together); env-names.ts imports nothing.
21
+ hostEnv: ["PI_BROWSER_CHROME", "CHROME_PATH", ...CHROME_ENV_NAMES],
20
22
  load: () => import("../local-chrome.js"),
21
23
  });
@@ -29,6 +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
+ readonly hostEnv: readonly ["PHONE_HARNESS_APKS", ...string[]];
33
33
  readonly load: () => Promise<typeof import("../phone-harness.js")>;
34
34
  };
@@ -1,5 +1,6 @@
1
1
  // The phone harness's descriptor: a cloud Android over adb, its sessions in a ledger the server keeps.
2
2
  import { defineProvider } from "../descriptor.js";
3
+ import { ADB_ENV_NAMES } from "./env-names.js";
3
4
  /** The groups a phone harness phone offers: phoned's, the driver it runs (daemon-android/), in its hello's order. */
4
5
  export const PHONE_GROUPS = ["exec", "screen", "input.keys", "input.touch", "apps", "ui"];
5
6
  /** The phone harness's Android: a phone computer when its setting names no image. */
@@ -19,7 +20,8 @@ export const PHONE_HARNESS = defineProvider({
19
20
  // The phone is driven by adb from the server's machine (the module's adb option, adb on PATH by default). Google
20
21
  // builds platform-tools for x86-64 Linux, macOS and x86-64 Windows alone.
21
22
  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"],
23
+ // The APKs every phone installs, files on this machine each pinned by its sha256: the operator's setting alone. And
24
+ // what adb reads (ADB_ENV_NAMES), the only environment an adb the provider runs starts with.
25
+ hostEnv: ["PHONE_HARNESS_APKS", ...ADB_ENV_NAMES],
24
26
  load: () => import("../phone-harness.js"),
25
27
  });
@@ -10,6 +10,13 @@ export declare const EGRESS_LABEL = "agentrun.computer.egress";
10
10
  /** Where the computer mounts the volume, read-only, and the proxy's socket in it: what init's relay connects to. */
11
11
  export declare const EGRESS_MOUNT = "/opt/agentrun/egress";
12
12
  export declare const EGRESS_SOCKET = "/opt/agentrun/egress/egress.sock";
13
+ /**
14
+ * `docker run`'s `--env` for the proxy variables, each set empty: the docker CLI fills in each one a run does not set
15
+ * itself from config.json's `proxies` (DOCKER_CONFIG, else HOME's .docker), so without these a computer, and its
16
+ * proxy, would hold the host's docker proxy, a credential in its URL included. A fenced computer's programs get their
17
+ * proxy from init's relay alone.
18
+ */
19
+ export declare const NO_CONFIG_PROXY: readonly string[];
13
20
  /** Init's flag for the relay: computerd init --egress <socket>. */
14
21
  export declare const RELAY_FLAG = "--egress";
15
22
  /** The most entries of each kind an allowlist holds: Docker's own bound, so the list fits one argv element. */
@@ -35,6 +35,13 @@ export const EGRESS_LABEL = "agentrun.computer.egress";
35
35
  /** Where the computer mounts the volume, read-only, and the proxy's socket in it: what init's relay connects to. */
36
36
  export const EGRESS_MOUNT = "/opt/agentrun/egress";
37
37
  export const EGRESS_SOCKET = `${EGRESS_MOUNT}/egress.sock`;
38
+ /**
39
+ * `docker run`'s `--env` for the proxy variables, each set empty: the docker CLI fills in each one a run does not set
40
+ * itself from config.json's `proxies` (DOCKER_CONFIG, else HOME's .docker), so without these a computer, and its
41
+ * proxy, would hold the host's docker proxy, a credential in its URL included. A fenced computer's programs get their
42
+ * proxy from init's relay alone.
43
+ */
44
+ export const NO_CONFIG_PROXY = Object.freeze(["HTTP_PROXY", "http_proxy", "HTTPS_PROXY", "https_proxy", "FTP_PROXY", "ftp_proxy", "NO_PROXY", "no_proxy", "ALL_PROXY", "all_proxy"].flatMap((name) => ["--env", `${name}=`]));
38
45
  /** Init's flag for the relay: computerd init --egress <socket>. */
39
46
  export const RELAY_FLAG = "--egress";
40
47
  /** The most entries of each kind an allowlist holds: Docker's own bound, so the list fits one argv element. */
@@ -195,6 +202,7 @@ export function egressRunArgs({ name, user, image, allow, local, deadline, code,
195
202
  for (const [key, value] of Object.entries(labels))
196
203
  args.push("--label", `${key}=${value}`);
197
204
  args.push("--user", user, "--read-only", "--cap-drop", "ALL", "--security-opt", "no-new-privileges", "--ipc", "private", "--cgroupns", "private");
205
+ args.push(...NO_CONFIG_PROXY);
198
206
  const memory = `${PROXY_MEMORY_MB}m`;
199
207
  args.push("--pids-limit", String(PROXY_PIDS), "--memory", memory, "--memory-swap", memory);
200
208
  args.push("--cpu-period", String(PROXY_CPU_PERIOD_US), "--cpu-quota", String(PROXY_CPU_QUOTA_US), "--ulimit", `nofile=${PROXY_NOFILE}:${PROXY_NOFILE}`);
@@ -1,4 +1,5 @@
1
1
  import { type Result } from "../result.js";
2
+ import { type HostEnv } from "../child-env.js";
2
3
  /** The repository every recipe's image is tagged in. */
3
4
  export declare const IMAGE_REPOSITORY = "agentrun-computer";
4
5
  /** The label a recipe's image carries: the recipe's whole sha256. A computer made from the image carries it too. */
@@ -25,6 +26,9 @@ export type ImageSource = {
25
26
  export interface EnsureImageOptions {
26
27
  /** The docker CLI. */
27
28
  docker?: string;
29
+ /** The host's environment variables: each docker call holds the names docker reads of them (DOCKER_ENV_NAMES), and
30
+ * nothing else; without env, none. A pull's credential helper finds its credentials through these. */
31
+ env?: HostEnv;
28
32
  /** Ends this caller's wait; the last caller's abort stops the build or pull. */
29
33
  signal?: AbortSignal;
30
34
  /** The flight's bound, when this call starts it; default IMAGE_TIMEOUT_MS. */
@@ -46,4 +50,4 @@ export declare function imageSourceProblem(source: unknown): string | undefined;
46
50
  * The image ready in Docker: its tag, for create's spec.image. A recipe is built when Docker has no image of it under its
47
51
  * tag; an image by name is pulled when Docker has none. Concurrent callers share one flight; see the top of this file.
48
52
  */
49
- export declare function ensureImage(source: ImageSource, { docker, signal, timeoutMs, onWait }?: EnsureImageOptions): Promise<Result<string>>;
53
+ export declare function ensureImage(source: ImageSource, { docker, env, signal, timeoutMs, onWait }?: EnsureImageOptions): Promise<Result<string>>;
@@ -19,6 +19,7 @@
19
19
  import { execFile } from "node:child_process";
20
20
  import { createHash } from "node:crypto";
21
21
  import { failFor, ok, vendorFail } from "../result.js";
22
+ import { dockerEnv } from "../child-env.js";
22
23
  /** This module's failures: one with code vendor names Docker. */
23
24
  const fail = failFor("docker");
24
25
  /** The repository every recipe's image is tagged in. */
@@ -98,7 +99,7 @@ function sourceOf(source) {
98
99
  * The image ready in Docker: its tag, for create's spec.image. A recipe is built when Docker has no image of it under its
99
100
  * tag; an image by name is pulled when Docker has none. Concurrent callers share one flight; see the top of this file.
100
101
  */
101
- export async function ensureImage(source, { docker = "docker", signal, timeoutMs = IMAGE_TIMEOUT_MS, onWait } = {}) {
102
+ export async function ensureImage(source, { docker = "docker", env, signal, timeoutMs = IMAGE_TIMEOUT_MS, onWait } = {}) {
102
103
  const checked = sourceOf(source);
103
104
  if (typeof checked === "string")
104
105
  return fail("invalid", checked);
@@ -107,12 +108,15 @@ export async function ensureImage(source, { docker = "docker", signal, timeoutMs
107
108
  }
108
109
  if (signal?.aborted)
109
110
  return fail("aborted", `the wait for ${checked.tag} was aborted before it began`);
110
- const key = JSON.stringify([docker, checked.kind, checked.kind === "recipe" ? checked.hash : checked.tag]);
111
+ // The environment docker is started with is part of the flight: two Docker hosts (DOCKER_HOST, DOCKER_CONTEXT) never
112
+ // share one pull or build. Its names are sorted, so the same environment is the same flight.
113
+ const childEnvOf = dockerEnv(env);
114
+ const key = JSON.stringify([docker, Object.entries(childEnvOf).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)), checked.kind, checked.kind === "recipe" ? checked.hash : checked.tag]);
111
115
  let flight = flights.get(key);
112
116
  // A flight every caller left is stopping: a new caller starts its own.
113
117
  if (flight === undefined || flight.controller.signal.aborted) {
114
118
  const crew = { controller: new AbortController(), waiting: 0, toTell: new Set() };
115
- const started = Object.assign(crew, { result: fly(docker, checked, timeoutMs, crew) });
119
+ const started = Object.assign(crew, { result: fly(docker, childEnvOf, checked, timeoutMs, crew) });
116
120
  flight = started;
117
121
  flights.set(key, started);
118
122
  void started.result.finally(() => {
@@ -176,14 +180,14 @@ export async function ensureImage(source, { docker = "docker", signal, timeoutMs
176
180
  * that fails asks Docker once more: another process may have tagged the image first (Docker 29's containerd image store
177
181
  * fails the loser of that race with "already exists"), and an image of this source under the tag is the answer.
178
182
  */
179
- async function fly(docker, source, timeoutMs, flight) {
183
+ async function fly(docker, env, source, timeoutMs, flight) {
180
184
  const { controller } = flight;
181
185
  let late = false;
182
186
  const timer = setTimeout(() => {
183
187
  late = true;
184
188
  controller.abort();
185
189
  }, timeoutMs);
186
- const call = (args, input) => run(docker, args, controller.signal, () => late, input);
190
+ const call = (args, input) => run(docker, env, args, controller.signal, () => late, input);
187
191
  const inspect = () => call(["image", "inspect", "--format", "{{json .Config.Labels}}", source.tag]);
188
192
  const ready = (answer) => answer.code === 0 && (source.kind === "image" || labelsOf(answer.stdout)[RECIPE_LABEL] === source.hash);
189
193
  try {
@@ -218,10 +222,10 @@ async function fly(docker, source, timeoutMs, flight) {
218
222
  clearTimeout(timer);
219
223
  }
220
224
  }
221
- /** `docker` with args, the input on its stdin, killed with SIGKILL when the signal aborts. */
222
- function run(docker, args, signal, late, input) {
225
+ /** `docker` with args, the input on its stdin, killed with SIGKILL when the signal aborts; `env` is its whole environment. */
226
+ function run(docker, env, args, signal, late, input) {
223
227
  return new Promise((resolve) => {
224
- const child = execFile(docker, args, { encoding: "utf8", signal, killSignal: "SIGKILL", maxBuffer: 32 * 1024 * 1024 }, (error, stdout, stderr) => {
228
+ const child = execFile(docker, args, { env, encoding: "utf8", signal, killSignal: "SIGKILL", maxBuffer: 32 * 1024 * 1024 }, (error, stdout, stderr) => {
225
229
  if (error === null)
226
230
  return resolve({ code: 0, stdout, stderr });
227
231
  const failed = error;