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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/README.md +101 -76
  2. package/box/README.md +2 -1
  3. package/box/recipe.d.mts +5 -0
  4. package/dist/agent37.d.ts +17 -4
  5. package/dist/agent37.js +96 -16
  6. package/dist/box-image.d.ts +14 -0
  7. package/dist/box-image.js +24 -0
  8. package/dist/computerd-linux-amd64 +0 -0
  9. package/dist/computerd-linux-arm64 +0 -0
  10. package/dist/computerd.json +2 -2
  11. package/dist/conformance/agent37.d.ts +9 -4
  12. package/dist/conformance/agent37.js +23 -11
  13. package/dist/conformance/browserbase.js +3 -3
  14. package/dist/conformance/cases/apps.d.ts +1 -1
  15. package/dist/conformance/cases/apps.js +1 -1
  16. package/dist/conformance/cases/isolation.d.ts +18 -3
  17. package/dist/conformance/cases/isolation.js +57 -6
  18. package/dist/conformance/cases/mount.js +4 -2
  19. package/dist/conformance/cases/provider.js +41 -0
  20. package/dist/conformance/cli.js +6 -5
  21. package/dist/conformance/e2b.js +9 -4
  22. package/dist/conformance/exec-stream.d.ts +7 -0
  23. package/dist/conformance/exec-stream.js +8 -1
  24. package/dist/conformance/kernel.js +2 -2
  25. package/dist/conformance/modal.js +1 -1
  26. package/dist/conformance/orgo.js +2 -2
  27. package/dist/daytona.d.ts +0 -5
  28. package/dist/daytona.js +16 -27
  29. package/dist/descriptor.d.ts +5 -3
  30. package/dist/descriptors/agent37.d.ts +3 -11
  31. package/dist/descriptors/agent37.js +9 -10
  32. package/dist/descriptors/daytona.d.ts +1 -1
  33. package/dist/descriptors/daytona.js +5 -2
  34. package/dist/descriptors/docker.d.ts +13 -1
  35. package/dist/descriptors/docker.js +3 -1
  36. package/dist/descriptors/e2b.d.ts +2 -9
  37. package/dist/descriptors/e2b.js +8 -8
  38. package/dist/descriptors/index.d.ts +21 -19
  39. package/dist/descriptors/index.js +1 -3
  40. package/dist/descriptors/modal.d.ts +2 -6
  41. package/dist/descriptors/modal.js +8 -6
  42. package/dist/descriptors/orgo.js +2 -1
  43. package/dist/docker/egress-main.js +23 -15
  44. package/dist/docker/egress.d.ts +6 -4
  45. package/dist/docker/egress.js +24 -16
  46. package/dist/docker/inspect.d.ts +2 -2
  47. package/dist/docker/inspect.js +5 -5
  48. package/dist/docker.d.ts +6 -5
  49. package/dist/docker.js +12 -11
  50. package/dist/e2b.d.ts +12 -2
  51. package/dist/e2b.js +42 -19
  52. package/dist/host.d.ts +54 -41
  53. package/dist/hosted/network.d.ts +23 -0
  54. package/dist/hosted/network.js +77 -0
  55. package/dist/hosted/process.d.ts +2 -0
  56. package/dist/hosted/process.js +5 -0
  57. package/dist/hosted/provider.d.ts +6 -4
  58. package/dist/hosted/provider.js +244 -136
  59. package/dist/hosted/rest.d.ts +10 -2
  60. package/dist/hosted/rest.js +9 -4
  61. package/dist/hosted/scripts.d.ts +19 -7
  62. package/dist/hosted/scripts.js +55 -18
  63. package/dist/{agent37-ssh.d.ts → hosted/ssh-exec.d.ts} +19 -9
  64. package/dist/{agent37-ssh.js → hosted/ssh-exec.js} +38 -19
  65. package/dist/hosted/values.d.ts +21 -0
  66. package/dist/hosted/values.js +55 -0
  67. package/dist/index.d.ts +1 -1
  68. package/dist/index.js +1 -1
  69. package/dist/isolation.d.ts +0 -2
  70. package/dist/isolation.js +3 -4
  71. package/dist/modal.d.ts +8 -2
  72. package/dist/modal.js +21 -15
  73. package/dist/mount-archil.d.ts +5 -4
  74. package/dist/mount-archil.js +5 -6
  75. package/dist/orgo.js +6 -4
  76. package/dist/providers.d.ts +4 -1
  77. package/dist/surface/api.d.ts +0 -9
  78. package/dist/surface/core.d.ts +7 -2
  79. package/dist/surface/core.js +12 -4
  80. package/dist/surface/index.d.ts +1 -1
  81. package/dist/surface/index.js +1 -1
  82. package/dist/surface/script.d.ts +4 -0
  83. package/dist/surface/script.js +9 -3
  84. package/package.json +1 -1
  85. package/box/build-agent37.mjs +0 -158
package/dist/agent37.js CHANGED
@@ -1,4 +1,4 @@
1
- // The Agent37 host: Agent37 Cloud instances (kind linux, or kind desktop on our box template, agentrun-box, whose Xvfb
1
+ // The Agent37 host: Agent37 Cloud instances (kind linux, or kind desktop on our box template, agentrun-box-<hash>, whose Xvfb
2
2
  // the adapter starts through the daemon), each a whole VM by default (type "vm"), or a gVisor sandbox
3
3
  // (type "default"). The control plane is Agent37's REST API over fetch (https://api.agent37.com/v1, a Bearer key);
4
4
  // every command (the daemon's upload, its install, init's start, the stdio bridge) goes over SSH, as root, through the
@@ -10,14 +10,16 @@
10
10
  // (./hosted/provider.ts). Every vendor fact here is cited in the README's Agent37 section.
11
11
  import { createHash } from "node:crypto";
12
12
  import { Duplex } from "node:stream";
13
- import { pemOf, SshExec, SshTunnelError } from "./agent37-ssh.js";
13
+ import { boxImageRef, boxRecipeHash } from "./box-image.js";
14
14
  import { AGENT37, AGENT37_BASE_TEMPLATE } from "./descriptors/agent37.js";
15
15
  import { DEADLINE_LABEL, show } from "./drift.js";
16
16
  import { HostError } from "./host.js";
17
17
  import { orThrow } from "./hosted/process.js";
18
18
  import { jsonOf, rest } from "./hosted/rest.js";
19
19
  import { HostedProvider } from "./hosted/provider.js";
20
+ import { pemOf, SshExec, SshTunnelError } from "./hosted/ssh-exec.js";
20
21
  import { dateOf, DOMAIN, isWhole } from "./hosted/values.js";
22
+ import { failFor, ok } from "./result.js";
21
23
  /** Not a literal, so no type checker or bundler resolves ssh2 from this package. */
22
24
  const SSH2_PACKAGE = "ssh2";
23
25
  const DEFAULT_API_URL = "https://api.agent37.com";
@@ -39,13 +41,25 @@ const SHAPES = [
39
41
  { cpu: 4, memory: 32 },
40
42
  ];
41
43
  const MAX_CPUS = 4;
42
- /** metadata's cap, serialized (docs: instances/edit, "up to 4 KB serialized"). */
44
+ /**
45
+ * metadata's cap, serialized (docs: instances/edit, "up to 4 KB serialized"): check() holds the names and values to it,
46
+ * and create the JSON, its quotes and commas too.
47
+ */
43
48
  const METADATA_MAX_BYTES = 4096;
44
49
  /** A VM boots inside the create's POST, which answers once it runs (docs: instances/create, Defaults). */
45
50
  const DEFAULT_CREATE_MS = 300_000;
46
51
  /** How much a tunnel may hold unsent before a write waits for it (the WebSocket's bufferedAmount). */
47
52
  const TUNNEL_HIGH_WATER = 1024 * 1024;
48
53
  const TUNNEL_POLL_MS = 10;
54
+ /**
55
+ * A registration copies the image into the workspace's storage before it answers, "up to a few minutes for a large
56
+ * image" (docs: templates, Register a workspace template): the POST's bound, and the wait on another's registration.
57
+ */
58
+ const REGISTER_MS = 15 * 60_000;
59
+ /** One read of a template. */
60
+ const TEMPLATE_READ_MS = 30_000;
61
+ /** How often a template another registration is making is read again. */
62
+ const TEMPLATE_POLL_MS = 1_000;
49
63
  /** An id held to Agent37's form before it reaches a URL or a host name (an id is also a DNS label here): not_found else. */
50
64
  function instanceId(id) {
51
65
  if (!INSTANCE_ID.test(id))
@@ -209,7 +223,7 @@ class Agent37Host {
209
223
  #declared;
210
224
  constructor(options) {
211
225
  this.#apiKey = options.apiKey;
212
- this.#ssh = new SshExec({ ssh2: options.ssh2, privateKey: options.sshKey, tunnelOf: (id) => this.#tunnel(id) });
226
+ this.#ssh = new SshExec({ ssh2: options.ssh2, loginOf: () => ({ username: "root", privateKey: options.sshKey }), tunnelOf: (id) => this.#tunnel(id) });
213
227
  this.#client = rest({
214
228
  base: options.apiUrl,
215
229
  headers: () => ({ Authorization: `Bearer ${options.apiKey}`, Accept: "application/json" }),
@@ -225,19 +239,17 @@ class Agent37Host {
225
239
  this.#WebSocket = options.WebSocket;
226
240
  this.#proxyDomain = options.proxyDomain;
227
241
  this.#declared = { type: options.type, region: options.region };
228
- const runtime = options.type === "vm" ? "vm" : "gvisor";
229
242
  this.facts = {
230
243
  daemon: "child",
231
- isolation: runtime,
244
+ // The adapter holds the probe's kernel to it: gVisor's for type default, never for a VM.
245
+ isolation: options.type === "vm" ? "vm" : "gvisor",
232
246
  lifetime: "janitor",
233
247
  maxLifetimeMs: DAY_MS,
234
248
  arch: "amd64",
235
249
  vendorAgentPorts: [AGENT37_SSH_PORT, AGENT37_TTYD_PORT],
236
- // The box template has xfwm4 (box/build-agent37.mjs): the apps an agent opens are framed and focused.
250
+ // The box template is the box image (box/Dockerfile), which has xfwm4: the apps an agent opens are framed and focused.
237
251
  windowManager: true,
238
- specFields: ["cpus", "memoryMb"],
239
- labelRules: { maxBytes: METADATA_MAX_BYTES, measure: "json" },
240
- runtime: () => runtime,
252
+ labels: { bytes: METADATA_MAX_BYTES },
241
253
  };
242
254
  }
243
255
  errorCode(error) {
@@ -250,7 +262,7 @@ class Agent37Host {
250
262
  ws.binaryType = "arraybuffer";
251
263
  return { ...tunnelOf(ws, host), host };
252
264
  }
253
- /** argv as root over SSH (agent37-ssh.ts): one connection per instance through its tunnel, shared by its execs. */
265
+ /** argv as root over SSH (hosted/ssh-exec.ts): one connection per instance through its tunnel, shared by its execs. */
254
266
  async exec(id, argv, ctx) {
255
267
  return this.#ssh.exec(instanceId(id), argv, ctx);
256
268
  }
@@ -262,7 +274,7 @@ class Agent37Host {
262
274
  throw new HostError("vendor", `${method} ${path} answered ${answer.status} with no JSON body`);
263
275
  return parsed;
264
276
  }
265
- /** An Agent37 template is a name, with an optional @<version>; a size is one of Agent37's four shapes. The adapter holds metadata to 4 KB (labelRules). */
277
+ /** An Agent37 template is a name, with an optional @<version>; a size is one of Agent37's four shapes. The adapter holds metadata to 4 KB (facts.labels.bytes). */
266
278
  check(given) {
267
279
  const refusals = [];
268
280
  const { image, cpus, memoryMb } = given;
@@ -279,10 +291,14 @@ class Agent37Host {
279
291
  }
280
292
  /**
281
293
  * POST /v1/instances: the template, the type and region, the size when the spec asks one, the request's name as the
282
- * instance's name, the labels as metadata, deny-all (or allow-all for an Archil computer's root), auto-sleep off and
294
+ * instance's name, the labels as metadata, deny-all (or allow-all where the adapter asks egress: an Archil computer's root, or the
295
+ * egress proxy of a network open or a list), auto-sleep off and
283
296
  * no public port. It answers once the instance runs (docs: instances/create, Defaults).
284
297
  */
285
298
  async create(req, ctx) {
299
+ const bytes = Buffer.byteLength(JSON.stringify(req.labels));
300
+ if (bytes > METADATA_MAX_BYTES)
301
+ throw new HostError("invalid", `Agent37 holds an instance's metadata to ${METADATA_MAX_BYTES} bytes as JSON, and this one's would be ${bytes}: give shorter labels`);
286
302
  const shape = req.cpus !== undefined || req.memoryMb !== undefined ? shapeOf(req.cpus, req.memoryMb) : undefined;
287
303
  const made = await this.#rest("POST", "/v1/instances", {
288
304
  template: req.image,
@@ -291,7 +307,7 @@ class Agent37Host {
291
307
  ...(shape === undefined ? {} : { resources: { cpu: shape.cpu, memory: shape.memory } }),
292
308
  name: req.name,
293
309
  metadata: req.labels,
294
- network: req.network === "open" ? "allow-all" : "deny-all",
310
+ network: req.egress ? "allow-all" : "deny-all",
295
311
  auto_sleep: false,
296
312
  public_ports: [],
297
313
  }, ctx);
@@ -342,6 +358,45 @@ class Agent37Host {
342
358
  const instance = await this.#rest("GET", path, undefined, ctx);
343
359
  await this.#rest("PATCH", path, { metadata: { ...(instance.metadata ?? {}), [DEADLINE_LABEL]: endsAt.toISOString() } }, ctx);
344
360
  }
361
+ /** GET /v1/templates/{name}: whether the workspace has it (404: it has not), else a HostError in Agent37's words. */
362
+ async #hasTemplate(name, signal) {
363
+ const read = orThrow(await this.#client.call("GET", this.#client.url(`/v1/templates/${name}`), { timeoutMs: TEMPLATE_READ_MS, accept: (status) => status === 200 || status === 404 }, signal));
364
+ return read.status === 200;
365
+ }
366
+ /**
367
+ * The workspace template `name`, made from the public image `imageRef` when the workspace has none (docs: templates):
368
+ * GET it; on a 404, `registering` is told, then POST /v1/templates { name, image_ref }, which answers once Agent37 has
369
+ * copied the image into the workspace. A 409 is another registration of the name, which this waits for, reading the
370
+ * template until the workspace has it. Throws a HostError in Agent37's words.
371
+ */
372
+ async template(name, imageRef, registering, signal) {
373
+ if (await this.#hasTemplate(name, signal))
374
+ return;
375
+ registering();
376
+ const json = { name, image_ref: imageRef, description: `AgentRun's box image ${imageRef}, registered by the server that first needed it` };
377
+ const posted = orThrow(await this.#client.call("POST", this.#client.url("/v1/templates"), { json, timeoutMs: REGISTER_MS, accept: (status) => (status >= 200 && status < 300) || status === 409 }, signal));
378
+ if (posted.status !== 409)
379
+ return;
380
+ const end = Date.now() + REGISTER_MS;
381
+ while (!(await this.#hasTemplate(name, signal))) {
382
+ if (Date.now() > end)
383
+ throw new HostError("timeout", `another registration of ${name} was not done within ${REGISTER_MS / 60_000} minutes`);
384
+ await new Promise((resolve, reject) => {
385
+ const done = () => {
386
+ clearTimeout(timer);
387
+ reject(new HostError("aborted", `the wait on another registration of ${name} was aborted`));
388
+ };
389
+ const timer = setTimeout(() => {
390
+ signal?.removeEventListener("abort", done);
391
+ resolve();
392
+ }, TEMPLATE_POLL_MS);
393
+ if (signal?.aborted)
394
+ done();
395
+ else
396
+ signal?.addEventListener("abort", done, { once: true });
397
+ });
398
+ }
399
+ }
345
400
  }
346
401
  /**
347
402
  * An Agent37Provider from its options alone; it reads no environment. The key is options.apiKey and the SSH key
@@ -357,11 +412,36 @@ export async function create(options) {
357
412
  }
358
413
  /** The conformance CLI's module for Agent37: its live switch, the run's cap, its template and the drifted twin. */
359
414
  export const conformance = () => import("./conformance/agent37.js");
415
+ const fail = failFor(AGENT37.id);
360
416
  /**
361
- * Computers that are Agent37 instances, on the shared adapter. A spec's image is an Agent37 template's name:
362
- * "agent37-base", Agent37's plain Linux, for a sandbox; "agentrun-box", our box template with Xvfb, for a desktop.
417
+ * Computers that are Agent37 instances, on the shared adapter. A spec's image is an Agent37 template's name, such as
418
+ * "agent37-base", Agent37's plain Linux. A server starts every one from the template prepareImage() answers: our box
419
+ * image, registered in the key's own workspace.
363
420
  */
364
421
  export class Agent37Provider extends HostedProvider {
422
+ /**
423
+ * The provider contract's prepareImage (its descriptor declares it): the box image the release publishes
424
+ * (box-image.ts), as the workspace template agentrun-box-<recipe hash>, registered from the public image the first
425
+ * time the workspace needs it, so a new recipe is a new template and the one before is left as it is. ok with the
426
+ * template's name; onWait is told "pull" once, before a registration it waits on, never when the workspace has it.
427
+ * A sandbox and a desktop start from the same image.
428
+ */
429
+ async prepareImage(context = {}) {
430
+ const name = `agentrun-box-${boxRecipeHash()}`;
431
+ const ref = boxImageRef();
432
+ let registering = false;
433
+ try {
434
+ await this.host.template(name, ref, () => {
435
+ registering = true;
436
+ context.onWait?.("pull", ref);
437
+ }, context.signal);
438
+ return ok(name);
439
+ }
440
+ catch (error) {
441
+ const said = error instanceof Error ? error.message : String(error);
442
+ return fail(codeOf(error), registering ? `registering ${ref} as the Agent37 template ${name}: ${said}` : `reading the Agent37 template ${name}: ${said}`);
443
+ }
444
+ }
365
445
  constructor(options) {
366
446
  const { apiKey, sshKey, ssh2, fetch: fetcher = globalThis.fetch, WebSocket = globalThis.WebSocket, apiUrl = DEFAULT_API_URL, proxyDomain = DEFAULT_PROXY_DOMAIN, type = "vm", region = "us", timeouts = {}, ...rest } = options ?? {};
367
447
  if (typeof apiKey !== "string" || apiKey === "")
@@ -0,0 +1,14 @@
1
+ /** Where the release publishes the box image. */
2
+ export declare const BOX_IMAGE_REPOSITORY = "ghcr.io/parcha-ai/agentrun-box";
3
+ /** The box recipe's hash, 12 hex, read once from this package's box/ folder. */
4
+ export declare function boxRecipeHash(): string;
5
+ /** The published box image this package's recipe names: ghcr.io/parcha-ai/agentrun-box:<recipe hash>. */
6
+ export declare const boxImageRef: () => string;
7
+ /**
8
+ * The E2B team that publishes the box template: release.yml's box-e2b job builds the box image as the E2B template
9
+ * agentrun-archil-<recipe hash> (box/build-e2b.mjs --image --public) in this team, and makes it public, so any E2B
10
+ * account starts it as <team slug>/<template>. The slug is E2B's name for the publishing team.
11
+ */
12
+ export declare const BOX_E2B_PUBLISHER = "agentrun-oss";
13
+ /** The public E2B template of the box image this package's recipe names: <publisher>/agentrun-archil-<recipe hash>. */
14
+ export declare const boxE2bTemplate: () => string;
@@ -0,0 +1,24 @@
1
+ // The box image as the release publishes it (release.yml's box job): box/Dockerfile built for amd64 and pushed, public,
2
+ // as ghcr.io/parcha-ai/agentrun-box:<recipe hash>. The hash is box/recipe.mjs's, read from the box/ folder this package
3
+ // ships, so a server names the image its own release published. A provider whose computers start from it (Agent37
4
+ // registers it in the owner's workspace, Modal pulls it) asks for it by this name; E2B starts from the public template
5
+ // the release builds from it (boxE2bTemplate).
6
+ import { recipeHash } from "../box/recipe.mjs";
7
+ /** Where the release publishes the box image. */
8
+ export const BOX_IMAGE_REPOSITORY = "ghcr.io/parcha-ai/agentrun-box";
9
+ let hash;
10
+ /** The box recipe's hash, 12 hex, read once from this package's box/ folder. */
11
+ export function boxRecipeHash() {
12
+ hash ??= recipeHash();
13
+ return hash;
14
+ }
15
+ /** The published box image this package's recipe names: ghcr.io/parcha-ai/agentrun-box:<recipe hash>. */
16
+ export const boxImageRef = () => `${BOX_IMAGE_REPOSITORY}:${boxRecipeHash()}`;
17
+ /**
18
+ * The E2B team that publishes the box template: release.yml's box-e2b job builds the box image as the E2B template
19
+ * agentrun-archil-<recipe hash> (box/build-e2b.mjs --image --public) in this team, and makes it public, so any E2B
20
+ * account starts it as <team slug>/<template>. The slug is E2B's name for the publishing team.
21
+ */
22
+ export const BOX_E2B_PUBLISHER = "agentrun-oss";
23
+ /** The public E2B template of the box image this package's recipe names: <publisher>/agentrun-archil-<recipe hash>. */
24
+ export const boxE2bTemplate = () => `${BOX_E2B_PUBLISHER}/agentrun-archil-${boxRecipeHash()}`;
Binary file
Binary file
@@ -1,4 +1,4 @@
1
1
  {
2
- "version": "0.1.0-beta.38",
3
- "source": "sha256:95e013be031ee2a63d9f52a82e540cf0ed71f42cf82b40f93b8843673875c30a"
2
+ "version": "0.1.0-beta.39",
3
+ "source": "sha256:6f2da993375dbd1b37c02475505d8cdf406b97a4f3b5924b0147262e01da1d0c"
4
4
  }
@@ -8,7 +8,7 @@ export { ARCHIL_ENV } from "./archil.js";
8
8
  /** The environment this module reads, by name, each for the option its comment names, the live switch and the run's template. */
9
9
  export declare const AGENT37_ENV: {
10
10
  readonly live: "AGENTRUN_COMPUTER_LIVE_AGENT37";
11
- /** The template every computer of the run starts from; default agent37-base, or agentrun-box for kind desktop. */
11
+ /** The template every computer of the run starts from; default agent37-base, or the box template for kind desktop. */
12
12
  readonly template: "COMPUTER_AGENT37_TEMPLATE";
13
13
  /** kind: linux (default) or desktop. */
14
14
  readonly kind: "COMPUTER_AGENT37_KIND";
@@ -32,7 +32,7 @@ export declare const AGENT37_ENV: {
32
32
  /** The names this module reads, under the conformance modules' common name (ConformanceModule.ENV). */
33
33
  export declare const ENV: {
34
34
  readonly live: "AGENTRUN_COMPUTER_LIVE_AGENT37";
35
- /** The template every computer of the run starts from; default agent37-base, or agentrun-box for kind desktop. */
35
+ /** The template every computer of the run starts from; default agent37-base, or the box template for kind desktop. */
36
36
  readonly template: "COMPUTER_AGENT37_TEMPLATE";
37
37
  /** kind: linux (default) or desktop. */
38
38
  readonly kind: "COMPUTER_AGENT37_KIND";
@@ -72,8 +72,13 @@ export interface Agent37ModuleOptions extends Pick<Agent37Options, "ssh2" | "fet
72
72
  /** For mountFor("archil"): the disk's object API, or the SDK's Archil client, in place of the host's disk package. */
73
73
  archil?: Pick<ArchilRunFolderOptions, "objects" | "Archil" | "baseUrl">;
74
74
  }
75
- /** The template every computer of the run starts from: COMPUTER_AGENT37_TEMPLATE, or agentrun-box for kind desktop, else agent37-base. */
76
- export declare function conformanceImage({ env }?: Pick<Agent37ModuleOptions, "env">): string;
75
+ /**
76
+ * The template every computer of the run starts from: COMPUTER_AGENT37_TEMPLATE, else agent37-base, else for kind
77
+ * desktop the box template, which the run's provider registers in the key's workspace first (prepareImage, live).
78
+ */
79
+ export declare function conformanceImage(options?: Agent37ModuleOptions, { signal }?: {
80
+ signal?: AbortSignal;
81
+ }): Promise<string>;
77
82
  /** The provider the CLI runs; throws in words without the live switch, or when a setting is missing or wrong. */
78
83
  export declare function createProvider(options?: Agent37ModuleOptions): Promise<Agent37Provider>;
79
84
  /** The same provider uploading a daemon that reports version <version>-drift, for the drift.version case. */
@@ -1,6 +1,6 @@
1
1
  // Agent37 for the conformance CLI: `npm run conformance -w @parcha/agentrun-computer -- --provider agent37`.
2
2
  // It makes real instances, which bill per minute until deleted, so it runs only with AGENTRUN_COMPUTER_LIVE_AGENT37=1
3
- // and a key the lead has OKed, under COMPUTER_AGENT37_API_KEY, beside COMPUTER_AGENT37_SSH_KEY, the private half (its
3
+ // and a key for an account you can bill, under COMPUTER_AGENT37_API_KEY, beside COMPUTER_AGENT37_SSH_KEY, the private half (its
4
4
  // contents) of an SSH key registered on the same workspace. The provider reads no environment: this module reads its
5
5
  // own COMPUTER_AGENT37_* names (never AGENT37_API_KEY, which may hold another team's key) and passes each to create()
6
6
  // as its option. The live switch is checked first, before any other setting is read. The live sweep (sweep.ts,
@@ -11,15 +11,15 @@
11
11
  // ends an instance on its own: every computer of a run lives at most 30 minutes, by init's deadline and the janitor's
12
12
  // label, and the run's sweep deletes what is left.
13
13
  //
14
- // COMPUTER_AGENT37_KIND=desktop runs the desktop's cases (screen, input) on agentrun-box, the box template
15
- // box/build-agent37.mjs publishes in the key's workspace: build it there first, or name another with an X server in
16
- // COMPUTER_AGENT37_TEMPLATE.
14
+ // COMPUTER_AGENT37_KIND=desktop runs the desktop's cases (screen, input) on the box template, agentrun-box-<recipe
15
+ // hash>, which the run registers in the key's workspace first through the provider's prepareImage() (from the public
16
+ // image the release publishes), or on another with an X server named in COMPUTER_AGENT37_TEMPLATE.
17
17
  //
18
18
  // For the mount cases, mountFor("archil") makes a fresh run folder on the Archil disk COMPUTER_ARCHIL_DISK names, as
19
19
  // the E2B module does (./archil.ts); with no disk named it makes none, and the cases are skipped. An Archil computer
20
20
  // needs a provider whose daemon user is the tool user: COMPUTER_AGENT37_USER=2510:2510, the default.
21
21
  import { create, workspaceOf } from "../agent37.js";
22
- import { AGENT37_BASE_TEMPLATE, AGENT37_BOX_TEMPLATE } from "../descriptors/agent37.js";
22
+ import { AGENT37_BASE_TEMPLATE } from "../descriptors/agent37.js";
23
23
  import { archilRunFolder, archilSettings } from "./archil.js";
24
24
  import { buildDriftDaemon, DRIFT_VERSION } from "./drift-daemon.js";
25
25
  /** The Archil disk's settings for the mount cases, by name (COMPUTER_ARCHIL_*: all five, or none). */
@@ -27,7 +27,7 @@ export { ARCHIL_ENV } from "./archil.js";
27
27
  /** The environment this module reads, by name, each for the option its comment names, the live switch and the run's template. */
28
28
  export const AGENT37_ENV = {
29
29
  live: "AGENTRUN_COMPUTER_LIVE_AGENT37",
30
- /** The template every computer of the run starts from; default agent37-base, or agentrun-box for kind desktop. */
30
+ /** The template every computer of the run starts from; default agent37-base, or the box template for kind desktop. */
31
31
  template: "COMPUTER_AGENT37_TEMPLATE",
32
32
  /** kind: linux (default) or desktop. */
33
33
  kind: "COMPUTER_AGENT37_KIND",
@@ -87,16 +87,28 @@ export function settingsFromEnv(env = process.env) {
87
87
  export const CONFORMANCE_MAX_LIFETIME_MS = 30 * 60_000;
88
88
  /** For the run's report: what this configuration means for the suite. */
89
89
  export const conformanceNotes = [
90
- "agent37: every computer is an instance (type vm by default), made with network deny-all, auto-sleep off and no public port, read back from Agent37 and probed from inside; the daemon is a child, started over SSH through the platform's sshd (port 22022; it and the platform's web terminal on 7681 are declared as the vendor's agent), and every command goes over that SSH as root. Agent37 never ends an instance on its own: lifetime janitor, capped at 30 minutes for the run. No stream() (a screen is streamed through agentrun), so screen.stream is skipped. Kind desktop (COMPUTER_AGENT37_KIND=desktop) starts from agentrun-box, our box image as a template of the key's workspace (box/build-agent37.mjs), with Xvfb on :0 started through the daemon as the tool user.",
90
+ "agent37: every computer is an instance (type vm by default), made with network deny-all, auto-sleep off and no public port, read back from Agent37 and probed from inside; the daemon is a child, started over SSH through the platform's sshd (port 22022; it and the platform's web terminal on 7681 are declared as the vendor's agent), and every command goes over that SSH as root. Agent37 never ends an instance on its own: lifetime janitor, capped at 30 minutes for the run. No stream() (a screen is streamed through agentrun), so screen.stream is skipped. Kind desktop (COMPUTER_AGENT37_KIND=desktop) starts from agentrun-box-<recipe hash>, our box image registered as a template of the key's workspace (prepareImage), with Xvfb on :0 started through the daemon as the tool user.",
91
91
  ];
92
92
  function live(env) {
93
93
  if (env[AGENT37_ENV.live] !== "1") {
94
- throw new Error(`the Agent37 conformance module makes real instances, which bill until deleted: set ${AGENT37_ENV.live}=1, with a key the lead has OKed, to run it`);
94
+ throw new Error(`the Agent37 conformance module makes real instances, which bill until deleted: set ${AGENT37_ENV.live}=1, with a key for an account you can bill, to run it`);
95
95
  }
96
96
  }
97
- /** The template every computer of the run starts from: COMPUTER_AGENT37_TEMPLATE, or agentrun-box for kind desktop, else agent37-base. */
98
- export function conformanceImage({ env = process.env } = {}) {
99
- return env[AGENT37_ENV.template] || (env[AGENT37_ENV.kind] === "desktop" ? AGENT37_BOX_TEMPLATE : AGENT37_BASE_TEMPLATE);
97
+ /**
98
+ * The template every computer of the run starts from: COMPUTER_AGENT37_TEMPLATE, else agent37-base, else for kind
99
+ * desktop the box template, which the run's provider registers in the key's workspace first (prepareImage, live).
100
+ */
101
+ export async function conformanceImage(options = {}, { signal } = {}) {
102
+ const { env = process.env } = options;
103
+ const named = env[AGENT37_ENV.template];
104
+ if (named)
105
+ return named;
106
+ if (env[AGENT37_ENV.kind] !== "desktop")
107
+ return AGENT37_BASE_TEMPLATE;
108
+ const ready = await (await createProvider(options)).prepareImage(signal ? { signal } : {});
109
+ if (!ready.ok)
110
+ throw new Error(`the Agent37 box template: ${ready.error.message}`);
111
+ return ready.value;
100
112
  }
101
113
  /** The test doubles a caller hands in, each only when given. */
102
114
  const doubles = ({ ssh2, fetch, WebSocket, timeouts, onNote }) => ({
@@ -1,6 +1,6 @@
1
1
  // Browserbase for the conformance CLI: `npm run conformance -w @parcha/agentrun-computer -- --provider browserbase`.
2
- // It makes a real, billed Browserbase session, so it runs only with AGENTRUN_COMPUTER_LIVE_BROWSERBASE=1 and a key the
3
- // lead has OKed, under COMPUTER_BROWSERBASE_API_KEY (and COMPUTER_BROWSERBASE_PROJECT_ID for a direct key). The provider
2
+ // It makes a real, billed Browserbase session, so it runs only with AGENTRUN_COMPUTER_LIVE_BROWSERBASE=1 and a key for
3
+ // an account you can bill, under COMPUTER_BROWSERBASE_API_KEY (and COMPUTER_BROWSERBASE_PROJECT_ID for a direct key). The provider
4
4
  // reads no environment: this module reads its own COMPUTER_BROWSERBASE_* names (never BROWSERBASE_API_KEY, which may
5
5
  // hold another project's key) and passes each to create() as its option. The live switch is checked first, before any
6
6
  // other setting is read. The run makes one session, shared by every case, and releases it.
@@ -39,7 +39,7 @@ export function conformanceImage() {
39
39
  /** The provider the CLI runs; throws in words without the live switch, or when the key is missing. */
40
40
  export async function createProvider({ env = process.env, ...transport } = {}) {
41
41
  if (env[BROWSERBASE_ENV.live] !== "1") {
42
- throw new Error(`the Browserbase conformance module makes a real, billed session: set ${BROWSERBASE_ENV.live}=1, with a key the lead has OKed, to run it`);
42
+ throw new Error(`the Browserbase conformance module makes a real, billed session: set ${BROWSERBASE_ENV.live}=1, with a key for an account you can bill, to run it`);
43
43
  }
44
44
  return create({ ...settingsFromEnv(env), ...transport });
45
45
  }
@@ -6,7 +6,7 @@ import type { Case } from "../types.js";
6
6
  export declare function observeWrong(result: unknown): string | undefined;
7
7
  /**
8
8
  * The stock apps a Linux desktop may have, by their desktop file ids, any vendor's: the text editor and the terminal of
9
- * Xfce, which E2B Desktop's template and the box image (box/build-agent37.mjs) both carry, and xterm, which a bare
9
+ * Xfce, which E2B Desktop's template and the box image (box/Dockerfile) both carry, and xterm, which a bare
10
10
  * desktop has (the Docker suite's, test/fixtures/desktop).
11
11
  */
12
12
  export declare const DESKTOP_APPS: readonly string[];
@@ -107,7 +107,7 @@ export function observeWrong(result) {
107
107
  const foreground = async (t) => (await t.call("apps.list", {})).foreground;
108
108
  /**
109
109
  * The stock apps a Linux desktop may have, by their desktop file ids, any vendor's: the text editor and the terminal of
110
- * Xfce, which E2B Desktop's template and the box image (box/build-agent37.mjs) both carry, and xterm, which a bare
110
+ * Xfce, which E2B Desktop's template and the box image (box/Dockerfile) both carry, and xterm, which a bare
111
111
  * desktop has (the Docker suite's, test/fixtures/desktop).
112
112
  */
113
113
  export const DESKTOP_APPS = ["org.xfce.mousepad", "mousepad", "xfce4-terminal", "org.xfce.terminal", "xterm"];
@@ -1,9 +1,10 @@
1
1
  import type { ComputerClient } from "../../protocol.js";
2
2
  import type { Case, CaseContext } from "../types.js";
3
3
  /**
4
- * The unix sockets a program of the computer's user may connect to: the computer's own, computerd's and the Archil sync
5
- * socket (which only syncs). A network namespace does not cut a path socket, and every program in the namespace reaches
6
- * an abstract name (@...), so any other socket is a door out.
4
+ * The unix sockets a program of the computer's user may connect to: the computer's own, computerd's, the Archil sync
5
+ * socket (which only syncs) and, under network open or a list, the egress proxy's (which reaches the public internet
6
+ * alone, as the spec's network asked). A network namespace does not cut a path socket, and every program in the
7
+ * namespace reaches an abstract name (@...), so any other socket is a door out.
7
8
  */
8
9
  export declare const OWN_SOCKETS: readonly string[];
9
10
  /**
@@ -20,4 +21,18 @@ export declare const OUTSIDE_TARGETS: string[];
20
21
  * socket list or no listener list, or a search it could not finish, fails the check in words. The Archil case mount.archil-isolated-durable runs the same check on an Archil computer.
21
22
  */
22
23
  export declare function assertIsolated(t: CaseContext, client?: ComputerClient): Promise<void>;
24
+ /**
25
+ * What root runs or reads in a computer: the directories of root's PATH (the one init gets, hosted/scripts.ts, and
26
+ * Debian's), computerd, the root helpers an Archil image ships (the helper and the archil client it runs), and, where an
27
+ * image has them, the vendor's agent (E2B's envd) and init's table.
28
+ */
29
+ export declare const ROOT_RUNS: readonly string[];
30
+ /** The check's argv, for the paths given (default ROOT_RUNS). */
31
+ export declare const rootRunsArgv: (paths?: readonly string[]) => string[];
32
+ /**
33
+ * The computer's user can write nothing root runs (ROOT_RUNS), nor any directory above it: a program of its could
34
+ * otherwise change what root runs next. Checked as that user with `test -w`, on the computer `client` reaches (the case's
35
+ * own by default); every path read is recorded, and one it reads none of fails.
36
+ */
37
+ export declare function assertRootRunsClosed(t: CaseContext, client?: ComputerClient): Promise<void>;
23
38
  export declare const isolationCases: Case[];
@@ -1,14 +1,16 @@
1
1
  // A program the computer's user runs reaches none of the vendor's own agent, whose ports each provider declares
2
2
  // (capabilities().vendorAgentPorts), and no outside address, sees its own loopback alone, and finds nothing listening in
3
- // its own network but computerd: computerd init --own-network at work.
3
+ // its own network but computerd: computerd init --own-network at work. And it can write nothing root runs.
4
4
  import { DAEMON_IN_COMPUTER, SOCKET_DIR } from "../../drift.js";
5
- import { ARCHIL_SYNC_SOCKET } from "../../mount-archil.js";
5
+ import { EGRESS_PROXY_SOCKET } from "../../hosted/network.js";
6
+ import { ARCHIL_HELPER, ARCHIL_SYNC_SOCKET } from "../../mount-archil.js";
6
7
  /**
7
- * The unix sockets a program of the computer's user may connect to: the computer's own, computerd's and the Archil sync
8
- * socket (which only syncs). A network namespace does not cut a path socket, and every program in the namespace reaches
9
- * an abstract name (@...), so any other socket is a door out.
8
+ * The unix sockets a program of the computer's user may connect to: the computer's own, computerd's, the Archil sync
9
+ * socket (which only syncs) and, under network open or a list, the egress proxy's (which reaches the public internet
10
+ * alone, as the spec's network asked). A network namespace does not cut a path socket, and every program in the
11
+ * namespace reaches an abstract name (@...), so any other socket is a door out.
10
12
  */
11
- export const OWN_SOCKETS = [`${SOCKET_DIR}/computerd.sock`, ARCHIL_SYNC_SOCKET];
13
+ export const OWN_SOCKETS = [`${SOCKET_DIR}/computerd.sock`, ARCHIL_SYNC_SOCKET, EGRESS_PROXY_SOCKET];
12
14
  /**
13
15
  * The outside the case also probes: a public IP literal on 443, and a DNS name on 443, which a program could reach only
14
16
  * through a resolver and a route its own network does not have.
@@ -115,6 +117,46 @@ async function displaySocket(client) {
115
117
  const number = /^:(\d{1,4})(?:\.\d{1,4})?$/.exec(hello.value.display ?? "")?.[1];
116
118
  return number === undefined ? undefined : `/tmp/.X11-unix/X${number}`;
117
119
  }
120
+ /**
121
+ * What root runs or reads in a computer: the directories of root's PATH (the one init gets, hosted/scripts.ts, and
122
+ * Debian's), computerd, the root helpers an Archil image ships (the helper and the archil client it runs), and, where an
123
+ * image has them, the vendor's agent (E2B's envd) and init's table.
124
+ */
125
+ export const ROOT_RUNS = ["/usr/local/sbin", "/usr/local/bin", "/usr/sbin", "/usr/bin", "/sbin", "/bin", DAEMON_IN_COMPUTER, ARCHIL_HELPER, "/usr/bin/archil", "/usr/bin/envd", "/etc/inittab"];
126
+ /** Each path given that is there, then every directory above it, each as `writable <path>` or `closed <path>`: `test -w`
127
+ * as the computer's user, and nothing written. A path on a read-only mount is closed: BusyBox's `test -w` reads the
128
+ * mode bits alone, so the mount's options are read from /proc/self/mountinfo (the longest mount point above the path,
129
+ * its own options and its superblock's). */
130
+ const ROOT_RUNS_SCRIPT = [
131
+ "# agentrun-conformance: root-runs",
132
+ "ro() { r=$(readlink -f \"$1\" 2>/dev/null); awk -v p=\"${r:-$1}\" '{ m = $5; gsub(/\\\\040/, \" \", m); if ((p == m || m == \"/\" || index(p, m \"/\") == 1) && length(m) >= n) { n = length(m); o = $6; for (i = 7; i < NF; i++) if ($i == \"-\") { o = o \",\" $(i + 3); break } } } END { exit !(o ~ /(^|,)ro(,|$)/) }' /proc/self/mountinfo 2>/dev/null; }",
133
+ 'for p in "$@"; do',
134
+ '\t[ -e "$p" ] || [ -L "$p" ] || continue',
135
+ "\tx=$p",
136
+ "\twhile :; do",
137
+ '\t\tif [ -w "$x" ] && ! ro "$x"; then echo "writable $x"; else echo "closed $x"; fi',
138
+ '\t\t[ "$x" = / ] && break',
139
+ "\t\tx=${x%/*}; x=${x:-/}",
140
+ "\tdone",
141
+ "done",
142
+ ].join("\n");
143
+ /** The check's argv, for the paths given (default ROOT_RUNS). */
144
+ export const rootRunsArgv = (paths = ROOT_RUNS) => ["sh", "-c", ROOT_RUNS_SCRIPT, "sh", ...paths];
145
+ /**
146
+ * The computer's user can write nothing root runs (ROOT_RUNS), nor any directory above it: a program of its could
147
+ * otherwise change what root runs next. Checked as that user with `test -w`, on the computer `client` reaches (the case's
148
+ * own by default); every path read is recorded, and one it reads none of fails.
149
+ */
150
+ export async function assertRootRunsClosed(t, client) {
151
+ const ran = await t.exec(rootRunsArgv(), { timeoutMs: t.patience }, client);
152
+ t.equal(ran.exitCode, 0, `the check's exit code (stderr: ${ran.err.trim()})`);
153
+ const said = (word) => [...new Set(ran.out.split("\n").flatMap((line) => (line.startsWith(`${word} `) ? [line.slice(word.length + 1)] : [])))];
154
+ const closed = said("closed");
155
+ const writable = said("writable");
156
+ t.observe(`what root runs, and the directories above it, as the computer's user: ${closed.length} closed (${closed.sort().join(", ")})${writable.length > 0 ? `; writable: ${writable.sort().join(", ")}` : ""}`);
157
+ t.assert(closed.length + writable.length > 0, `the check read no path: ${ran.out.slice(0, 200)}`);
158
+ t.assert(writable.length === 0, `the computer's user can write what root runs: ${writable.join(", ")}`);
159
+ }
118
160
  export const isolationCases = [
119
161
  {
120
162
  id: "isolation.vendor-agent",
@@ -125,4 +167,13 @@ export const isolationCases = [
125
167
  await assertIsolated(t);
126
168
  },
127
169
  },
170
+ {
171
+ id: "isolation.root-runs",
172
+ level: "core",
173
+ group: "isolation",
174
+ needs: ["exec"],
175
+ async run(t) {
176
+ await assertRootRunsClosed(t);
177
+ },
178
+ },
128
179
  ];
@@ -14,7 +14,7 @@ import { randomBytes } from "node:crypto";
14
14
  import { EPOCH_LABEL, RUN_LABEL, runLabels as claimLabels } from "../../labels.js";
15
15
  import { MOUNT_KINDS, readBackOf, WORKSPACE } from "../../mount.js";
16
16
  import { MAX_OUTPUT_BYTES } from "../../protocol.js";
17
- import { assertIsolated } from "./isolation.js";
17
+ import { assertIsolated, assertRootRunsClosed } from "./isolation.js";
18
18
  import { b64, CASE_LABEL, decode } from "./util.js";
19
19
  /** The claim epoch the run-folder cases make their computers under. */
20
20
  const EPOCH = 1;
@@ -169,7 +169,7 @@ const archilToken = mount("archil-token", async (t) => {
169
169
  }, { needs: ["mount:archil", "exec"], timeoutMs: 600_000 });
170
170
  /**
171
171
  * "isolated, and durable through the root side", on one Archil computer: a tool sees loopback alone and reaches neither a
172
- * vendor's agent nor any address; and a tool's write in /workspace, by a program (exec.run) and by files.write, is read
172
+ * vendor's agent nor any address, and can write nothing root runs; and a tool's write in /workspace, by a program (exec.run) and by files.write, is read
173
173
  * through the disk's file API right after the call returns, with no checkin. So the per-call sync goes out from the
174
174
  * archil client and serve, which run as root outside the tools' namespace.
175
175
  */
@@ -180,6 +180,8 @@ const archilIsolatedDurable = mount("archil-isolated-durable", async (t) => {
180
180
  // isolation.vendor-agent's own check, on this Archil computer: lo alone, refused at the vendor's agent and outside,
181
181
  // and no unix socket a tool connects to but the computer's own (computerd's, the sync socket).
182
182
  await assertIsolated(t, connected.client);
183
+ // isolation.root-runs' check too, where the Archil helper and client are there to check.
184
+ await assertRootRunsClosed(t, connected.client);
183
185
  const nonce = randomBytes(6).toString("hex");
184
186
  const ran = await t.exec(["sh", "-c", `printf '%s\\n' ${nonce} > exec-${nonce}.txt`], { cwd: WORKSPACE }, connected.client);
185
187
  t.equal(ran.exitCode, 0, `a program's write at ${WORKSPACE}: its exit code (${ran.err.trim()})`);
@@ -10,6 +10,24 @@ import { computerNameFor, runLifetimeMs } from "../../provider.js";
10
10
  import { b64, CASE_LABEL, decode } from "./util.js";
11
11
  /** Labels for one case's computers: the run's, and the case's own. */
12
12
  const own = (t, name) => ({ ...t.runLabels, [CASE_LABEL]: name });
13
+ /** Gets url with curl as the computer's user, through the proxy its programs are told of (no host bypasses it): curl's exit,
14
+ * the HTTP code and the CONNECT code. Undefined, observed, on a computer that is not Linux with exec, or where the image
15
+ * has no curl or no proxy is set. */
16
+ const CURL = `command -v curl >/dev/null 2>&1 || { echo nocurl; exit 0; }; [ -n "\${HTTPS_PROXY:-\${https_proxy:-}}" ] || { echo noproxy; exit 0; }; c=$(curl -sS -o /dev/null --noproxy '' --max-time 30 -w '%{http_code} %{http_connect}' "$1" 2>/dev/null); echo "$? $c"`;
17
+ async function curled(t, { client, hello }, url) {
18
+ if (hello.os !== "linux" || !hello.groups.includes("exec")) {
19
+ t.observe(`the computer runs ${hello.os}${hello.groups.includes("exec") ? "" : " with no exec"}, so the egress proxy's answers were not read with curl`);
20
+ return undefined;
21
+ }
22
+ const ran = t.ok(await client.call("exec.run", { argv: ["sh", "-c", CURL, "sh", url], timeoutMs: 60_000 }), `curl ${url}`);
23
+ const out = decode(ran.stdout).trim();
24
+ if (out === "nocurl" || out === "noproxy") {
25
+ t.observe(out === "nocurl" ? "the image has no curl, so the egress proxy's answers were not read" : "no proxy is set for the computer's programs: its open network is the vendor's own, with no egress proxy to read");
26
+ return undefined;
27
+ }
28
+ const [exit, code, connect] = out.split(" ");
29
+ return { exit: Number(exit), code: code ?? "", connect: connect ?? "" };
30
+ }
13
31
  const names = async (t, labels) => t
14
32
  .ok(await t.provider.list(labels), `list ${JSON.stringify(labels)}`)
15
33
  .map((info) => info.ref.name)
@@ -343,11 +361,34 @@ export const providerCases = [
343
361
  t.deepEqual(t.ok(await t.provider.list(labels), "list").map((info) => info.network), ["open"], "the network list reads back");
344
362
  const connected = await t.connect(ref);
345
363
  t.deepEqual(t.ok(await connected.client.call("ping", {}), "ping"), {}, "ping in an open computer");
364
+ // Where open goes through an egress proxy (the programs are told of one), it reaches the public internet alone:
365
+ // a name, with no resolver of the programs' own, and never metadata, a private address or the vendor's agent.
366
+ const web = await curled(t, connected, "https://example.com/");
367
+ if (web === undefined)
368
+ return;
369
+ t.equal(`${web.exit} ${web.code}`, "0 200", "curl by name to https://example.com/ through the egress proxy");
370
+ const refusedTargets = [
371
+ ["http://169.254.169.254/latest/meta-data/", "metadata (169.254.169.254), plain HTTP"],
372
+ ["https://169.254.169.254/", "metadata (169.254.169.254), CONNECT"],
373
+ ["https://10.0.0.1/", "a private address"],
374
+ ...(t.provider.capabilities().vendorAgentPorts ?? []).map((port) => [`http://127.0.0.1:${port}/`, `the vendor's agent's port ${port} on the loopback`]),
375
+ ];
376
+ for (const [url, what] of refusedTargets) {
377
+ const refused = await curled(t, connected, url);
378
+ t.assert(refused !== undefined && (refused.code === "403" || refused.connect === "403"), `${what}: the egress proxy refuses ${url} with 403, not ${JSON.stringify(refused)}`);
379
+ }
346
380
  }, { level: "full", needs: ["network:open"] }),
347
381
  provider("network-allow", async (t) => {
348
382
  const policy = { allow: ["example.com"] };
349
383
  const ref = await t.create({ labels: own(t, "allow"), network: policy });
350
384
  t.deepEqual(t.ok(await t.provider.network(ref), "network read-back"), policy, "the allowlist read back");
385
+ const connected = await t.connect(ref);
386
+ const listed = await curled(t, connected, "https://example.com/");
387
+ if (listed === undefined)
388
+ return;
389
+ t.equal(`${listed.exit} ${listed.code}`, "0 200", "curl by name to https://example.com/, on the list, through the egress proxy");
390
+ const off = await curled(t, connected, "https://example.org/");
391
+ t.equal(off?.connect, "403", "https://example.org/, off the list: the egress proxy refuses its CONNECT with 403");
351
392
  }, { level: "full", needs: ["network:allow"] }),
352
393
  provider("deadline", async (t) => {
353
394
  const labels = own(t, "deadline");