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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/README.md +341 -260
  2. package/box/Dockerfile +18 -1
  3. package/box/README.md +14 -0
  4. package/box/build-daytona.py +2 -2
  5. package/box/build-e2b.mjs +41 -18
  6. package/box/recipe.d.mts +5 -0
  7. package/box/recipe.mjs +43 -0
  8. package/dist/agent37.d.ts +18 -66
  9. package/dist/agent37.js +187 -464
  10. package/dist/box-image.d.ts +14 -0
  11. package/dist/box-image.js +24 -0
  12. package/dist/browserbase.d.ts +0 -6
  13. package/dist/browserbase.js +1 -5
  14. package/dist/client.d.ts +12 -3
  15. package/dist/client.js +39 -4
  16. package/dist/computerd-linux-amd64 +0 -0
  17. package/dist/computerd-linux-arm64 +0 -0
  18. package/dist/computerd.json +4 -0
  19. package/dist/conformance/agent37.d.ts +9 -4
  20. package/dist/conformance/agent37.js +23 -11
  21. package/dist/conformance/browserbase.js +3 -3
  22. package/dist/conformance/cases/apps.d.ts +6 -0
  23. package/dist/conformance/cases/apps.js +18 -5
  24. package/dist/conformance/cases/isolation.d.ts +22 -5
  25. package/dist/conformance/cases/isolation.js +97 -16
  26. package/dist/conformance/cases/mount.js +5 -3
  27. package/dist/conformance/cases/provider.js +41 -0
  28. package/dist/conformance/cli.js +72 -11
  29. package/dist/conformance/daytona.d.ts +9 -20
  30. package/dist/conformance/daytona.js +12 -21
  31. package/dist/conformance/e2b.js +9 -4
  32. package/dist/conformance/exec-stream.d.ts +52 -0
  33. package/dist/conformance/exec-stream.js +493 -0
  34. package/dist/conformance/kernel.js +2 -2
  35. package/dist/conformance/modal.js +1 -1
  36. package/dist/conformance/orgo.js +2 -2
  37. package/dist/conformance/sweep.js +8 -8
  38. package/dist/conformance/types.d.ts +2 -2
  39. package/dist/create-requests.d.ts +1 -1
  40. package/dist/daytona.d.ts +17 -133
  41. package/dist/daytona.js +396 -1452
  42. package/dist/descriptor.d.ts +11 -4
  43. package/dist/descriptor.js +7 -0
  44. package/dist/descriptors/agent37.d.ts +3 -11
  45. package/dist/descriptors/agent37.js +9 -10
  46. package/dist/descriptors/daytona.d.ts +7 -6
  47. package/dist/descriptors/daytona.js +14 -7
  48. package/dist/descriptors/docker.d.ts +13 -1
  49. package/dist/descriptors/docker.js +3 -1
  50. package/dist/descriptors/e2b.d.ts +2 -9
  51. package/dist/descriptors/e2b.js +8 -8
  52. package/dist/descriptors/index.d.ts +25 -24
  53. package/dist/descriptors/index.js +1 -3
  54. package/dist/descriptors/modal.d.ts +2 -6
  55. package/dist/descriptors/modal.js +8 -6
  56. package/dist/descriptors/orgo.js +2 -1
  57. package/dist/descriptors/shared.d.ts +1 -1
  58. package/dist/descriptors/shared.js +2 -2
  59. package/dist/desktop.d.ts +18 -4
  60. package/dist/desktop.js +89 -9
  61. package/dist/docker/egress-main.js +23 -15
  62. package/dist/docker/egress.d.ts +6 -4
  63. package/dist/docker/egress.js +24 -16
  64. package/dist/docker/inspect.d.ts +2 -2
  65. package/dist/docker/inspect.js +5 -5
  66. package/dist/docker.d.ts +6 -11
  67. package/dist/docker.js +13 -16
  68. package/dist/drift.js +4 -4
  69. package/dist/e2b.d.ts +22 -130
  70. package/dist/e2b.js +163 -243
  71. package/dist/host.d.ts +136 -104
  72. package/dist/host.js +8 -1
  73. package/dist/hosted/network.d.ts +23 -0
  74. package/dist/hosted/network.js +77 -0
  75. package/dist/hosted/process.d.ts +24 -8
  76. package/dist/hosted/process.js +80 -44
  77. package/dist/hosted/provider.d.ts +38 -22
  78. package/dist/hosted/provider.js +500 -341
  79. package/dist/hosted/rest.d.ts +74 -0
  80. package/dist/hosted/rest.js +126 -0
  81. package/dist/hosted/scripts.d.ts +21 -3
  82. package/dist/hosted/scripts.js +76 -14
  83. package/dist/hosted/ssh-exec.d.ts +99 -0
  84. package/dist/hosted/ssh-exec.js +464 -0
  85. package/dist/hosted/values.d.ts +26 -0
  86. package/dist/hosted/values.js +63 -0
  87. package/dist/index.d.ts +2 -2
  88. package/dist/index.js +2 -2
  89. package/dist/isolation.d.ts +0 -2
  90. package/dist/isolation.js +3 -4
  91. package/dist/kernel.d.ts +0 -6
  92. package/dist/kernel.js +1 -5
  93. package/dist/kinds.d.ts +3 -1
  94. package/dist/local-chrome.d.ts +0 -6
  95. package/dist/local-chrome.js +1 -5
  96. package/dist/modal.d.ts +15 -86
  97. package/dist/modal.js +67 -185
  98. package/dist/mount-archil.d.ts +13 -8
  99. package/dist/mount-archil.js +27 -17
  100. package/dist/mount.d.ts +10 -4
  101. package/dist/mount.js +8 -4
  102. package/dist/orgo.d.ts +0 -9
  103. package/dist/orgo.js +8 -13
  104. package/dist/phone-harness.d.ts +0 -6
  105. package/dist/phone-harness.js +0 -4
  106. package/dist/protocol.d.ts +4 -1
  107. package/dist/protocol.js +1 -0
  108. package/dist/provider.d.ts +2 -2
  109. package/dist/providers.d.ts +15 -13
  110. package/dist/screen-watch.js +34 -6
  111. package/dist/surface/api.d.ts +14 -11
  112. package/dist/surface/core.d.ts +23 -5
  113. package/dist/surface/core.js +105 -15
  114. package/dist/surface/index.d.ts +1 -1
  115. package/dist/surface/index.js +1 -1
  116. package/dist/surface/outline.d.ts +2 -0
  117. package/dist/surface/outline.js +2 -1
  118. package/dist/surface/script.d.ts +4 -0
  119. package/dist/surface/script.js +11 -3
  120. package/dist/ui-engine.js +19 -3
  121. package/package.json +2 -3
  122. package/box/build-agent37.mjs +0 -177
  123. package/dist/conformance/daytona-sweep.d.ts +0 -18
  124. package/dist/conformance/daytona-sweep.js +0 -126
@@ -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()}`;
@@ -1,6 +1,4 @@
1
1
  import { type BrowserComputerProvider, type BrowserDownloads, type BrowserProfiles, type BrowserStream, type ReleaseConfirm } from "./browser.js";
2
- import type { KindCapabilities } from "./kinds.js";
3
- import type { MountKind } from "./mount.js";
4
2
  import { type AttachedComputer, type CallContext, type ComputerCapabilities, type ComputerConnection, type ComputerInfo, type ComputerProvider, type ComputerRef, type ComputerSpec, type CreateContext, type CreatedComputer, type NetworkPolicy, type NetworkSpec, type Refusal, type ReleaseHow } from "./provider.js";
5
3
  import { type Result } from "./result.js";
6
4
  export declare const BROWSERBASE_API_URL = "https://api.browserbase.com";
@@ -16,10 +14,6 @@ export declare const metadataKey: (labelKey: string) => string;
16
14
  export declare const labelKey: (metadataKey: string) => string;
17
15
  /** Why labels cannot ride a Browserbase session's userMetadata, in words naming the label; undefined when they can. */
18
16
  export declare function browserbaseLabelsProblem(labels: unknown): string | undefined;
19
- /** A browser takes no mount. */
20
- export declare const MOUNT: readonly MountKind[];
21
- /** The one configuration it offers, its descriptor's: a browser with a CDP target and a live view. */
22
- export declare const CAPABILITIES: readonly KindCapabilities[];
23
17
  /** A session as Browserbase answers it; only what the provider reads. */
24
18
  export interface BrowserbaseSession {
25
19
  id: string;
@@ -64,10 +64,6 @@ export function browserbaseLabelsProblem(labels) {
64
64
  }
65
65
  return undefined;
66
66
  }
67
- /** A browser takes no mount. */
68
- export const MOUNT = BROWSERBASE.mounts;
69
- /** The one configuration it offers, its descriptor's: a browser with a CDP target and a live view. */
70
- export const CAPABILITIES = BROWSERBASE.capabilities;
71
67
  /** A plain id as Browserbase answers one (a context's, a download's): a token, never a path. */
72
68
  const plainId = (id) => typeof id === "string" && /^[A-Za-z0-9_.:-]{1,128}$/.test(id);
73
69
  /** Browserbase's v1 REST API over fetch: the default api. */
@@ -207,7 +203,7 @@ export class BrowserbaseProvider {
207
203
  isolation: "vm",
208
204
  os: "linux",
209
205
  daemon: "none",
210
- groups: [...CAPABILITIES[0].groups],
206
+ groups: [...BROWSERBASE.capabilities[0].groups],
211
207
  maxLifetimeMs: BROWSERBASE_MAX_LIFETIME_MS,
212
208
  release: ["delete"],
213
209
  browser: structuredClone(this.#browser),
package/dist/client.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { Readable, Writable } from "node:stream";
2
2
  import { type ComputerClient, type DaemonErrorKind, type DaemonMethod, type DaemonMethods, type UiActResult, type UiExpect, type UiNode, type UiObserveParams, type UiObserveResult, type UiRole, type UiStep, type UiTarget } from "./protocol.js";
3
- import { type Result } from "./result.js";
3
+ import { type ComputerError, type Result } from "./result.js";
4
4
  export interface DaemonStream {
5
5
  readable: Readable;
6
6
  writable: Writable;
@@ -8,10 +8,19 @@ export interface DaemonStream {
8
8
  export interface CallOptions {
9
9
  signal?: AbortSignal;
10
10
  }
11
+ /**
12
+ * How long past a call's own timeoutMs (exec.run's, process.wait's) the daemon has to answer it. The daemon answers by
13
+ * that bound itself, so a call still unanswered after this has a transport that hangs: it ends here as timeout, never
14
+ * at whatever ends the transport much later.
15
+ */
16
+ export declare const ANSWER_SLACK_MS = 5000;
17
+ /** Whether `error` is a timeout this client gave a call whose bound passed with no answer over the transport. */
18
+ export declare function unanswered(error: ComputerError): boolean;
11
19
  /**
12
20
  * Calls a daemon's methods. Each call gets its own id; replies may come in any order. An aborted call sends
13
- * $/cancelRequest and returns `aborted` at once; the daemon still ends what the call started. When the stream ends,
14
- * every pending and later call fails with `gone`. A line that is not a reply to a pending call is dropped.
21
+ * $/cancelRequest and returns `aborted` at once; the daemon still ends what the call started. A call whose params carry
22
+ * a timeoutMs and that has no answer ANSWER_SLACK_MS past it sends the same cancel and returns `timeout`. When the
23
+ * stream ends, every pending and later call fails with `gone`. A line that is not a reply to a pending call is dropped.
15
24
  */
16
25
  export declare class DaemonClient implements ComputerClient {
17
26
  #private;
package/dist/client.js CHANGED
@@ -1,5 +1,22 @@
1
1
  import { CANCEL_METHOD, JSONRPC_CODES, MAX_LINE_BYTES, } from "./protocol.js";
2
2
  import { fail, ok } from "./result.js";
3
+ /**
4
+ * How long past a call's own timeoutMs (exec.run's, process.wait's) the daemon has to answer it. The daemon answers by
5
+ * that bound itself, so a call still unanswered after this has a transport that hangs: it ends here as timeout, never
6
+ * at whatever ends the transport much later.
7
+ */
8
+ export const ANSWER_SLACK_MS = 5_000;
9
+ /** The timeout errors a client gave itself, a call's bound passed with no answer: never one the daemon answered. */
10
+ const UNANSWERED = new WeakSet();
11
+ /** Whether `error` is a timeout this client gave a call whose bound passed with no answer over the transport. */
12
+ export function unanswered(error) {
13
+ return UNANSWERED.has(error);
14
+ }
15
+ /** The bound of a call whose params carry their own timeoutMs, or undefined for a call with none. */
16
+ function boundOf(params) {
17
+ const own = params?.timeoutMs;
18
+ return typeof own === "number" && Number.isFinite(own) && own >= 0 ? { ms: own + ANSWER_SLACK_MS, own } : undefined;
19
+ }
3
20
  const KINDS = new Set([
4
21
  "not_found",
5
22
  "invalid",
@@ -28,8 +45,9 @@ function fromReply(error) {
28
45
  }
29
46
  /**
30
47
  * Calls a daemon's methods. Each call gets its own id; replies may come in any order. An aborted call sends
31
- * $/cancelRequest and returns `aborted` at once; the daemon still ends what the call started. When the stream ends,
32
- * every pending and later call fails with `gone`. A line that is not a reply to a pending call is dropped.
48
+ * $/cancelRequest and returns `aborted` at once; the daemon still ends what the call started. A call whose params carry
49
+ * a timeoutMs and that has no answer ANSWER_SLACK_MS past it sends the same cancel and returns `timeout`. When the
50
+ * stream ends, every pending and later call fails with `gone`. A line that is not a reply to a pending call is dropped.
33
51
  */
34
52
  export class DaemonClient {
35
53
  #writable;
@@ -58,18 +76,35 @@ export class DaemonClient {
58
76
  const line = `${JSON.stringify({ jsonrpc: "2.0", id, method, params })}\n`;
59
77
  if (Buffer.byteLength(line) - 1 > MAX_LINE_BYTES)
60
78
  return fail("limit", `the ${method} request is over the 1 MiB line limit`);
79
+ const bound = boundOf(params);
61
80
  return new Promise((resolve) => {
62
- const onAbort = () => {
81
+ let timer;
82
+ const giveUp = (result) => {
63
83
  if (!this.#pending.delete(id))
64
84
  return;
85
+ clearTimeout(timer);
86
+ signal?.removeEventListener("abort", onAbort);
65
87
  this.#write({ jsonrpc: "2.0", method: CANCEL_METHOD, params: { id } });
66
- resolve(fail("aborted", `${method} was aborted`));
88
+ resolve(result);
67
89
  };
90
+ const onAbort = () => giveUp(fail("aborted", `${method} was aborted`));
68
91
  this.#pending.set(id, (result) => {
92
+ clearTimeout(timer);
69
93
  signal?.removeEventListener("abort", onAbort);
70
94
  resolve(result);
71
95
  });
72
96
  signal?.addEventListener("abort", onAbort, { once: true });
97
+ if (bound !== undefined) {
98
+ const s = (ms) => `${ms / 1000} s`;
99
+ timer = setTimeout(() => {
100
+ const timedOut = fail("timeout", `${method} had no answer within ${s(bound.ms)} (its own timeout of ${s(bound.own)}, and ${s(ANSWER_SLACK_MS)} for the answer to come)`);
101
+ if (!timedOut.ok)
102
+ UNANSWERED.add(timedOut.error);
103
+ giveUp(timedOut);
104
+ }, bound.ms);
105
+ // The stream holds the process while a call waits on it; the bound alone never does.
106
+ timer.unref?.();
107
+ }
73
108
  this.#writable.write(line);
74
109
  });
75
110
  }
Binary file
Binary file
@@ -0,0 +1,4 @@
1
+ {
2
+ "version": "0.1.0-beta.39",
3
+ "source": "sha256:6f2da993375dbd1b37c02475505d8cdf406b97a4f3b5924b0147262e01da1d0c"
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
  }
@@ -4,4 +4,10 @@ import type { Case } from "../types.js";
4
4
  * and each node against UiNode, its bounds inside the window and its parent a node before it.
5
5
  */
6
6
  export declare function observeWrong(result: unknown): string | undefined;
7
+ /**
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/Dockerfile) both carry, and xterm, which a bare
10
+ * desktop has (the Docker suite's, test/fixtures/desktop).
11
+ */
12
+ export declare const DESKTOP_APPS: readonly string[];
7
13
  export declare const appsCases: Case[];
@@ -1,6 +1,7 @@
1
1
  // Apps: the fixture installs, is listed, comes to the front when launched and leaves it when terminated; ui.observe has
2
2
  // the protocol's shape, inside its window, with the fixture's button found by its id. A phone's stock Settings app is
3
- // listed, launched and terminated with no install, which needs the apps group alone: its launch is seen in ui.observe
3
+ // listed, launched and terminated with no install, which needs the apps group alone, and so is a Linux desktop's stock
4
+ // editor or terminal (DESKTOP_APPS), on any vendor: its launch is seen in ui.observe
4
5
  // (Settings' list) when the phone has the ui group, else in a screenshot that is not the one before. On a phone that
5
6
  // takes no fixture file the observation's shape is checked on Settings, with its rows found (settings.ts).
6
7
  import { MAX_UI_NODES, UI_FLAGS, UI_ROLES } from "../../protocol.js";
@@ -104,6 +105,18 @@ export function observeWrong(result) {
104
105
  return undefined;
105
106
  }
106
107
  const foreground = async (t) => (await t.call("apps.list", {})).foreground;
108
+ /**
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/Dockerfile) both carry, and xterm, which a bare
111
+ * desktop has (the Docker suite's, test/fixtures/desktop).
112
+ */
113
+ export const DESKTOP_APPS = ["org.xfce.mousepad", "mousepad", "xfce4-terminal", "org.xfce.terminal", "xterm"];
114
+ /** A stock app the computer lists: the first of DESKTOP_APPS on a desktop, a phone's Settings, or the case skips in words. */
115
+ function stockApp(t, listed) {
116
+ if (t.provider.capabilities().kind !== "desktop")
117
+ return settingsApp(t);
118
+ return DESKTOP_APPS.find((id) => listed.some((one) => one.id === id)) ?? t.skip(`this desktop lists none of the stock apps the case knows (${DESKTOP_APPS.join(", ")})`);
119
+ }
107
120
  export const appsCases = [
108
121
  {
109
122
  id: "apps.install-launch",
@@ -130,12 +143,12 @@ export const appsCases = [
130
143
  group: "apps",
131
144
  needs: ["apps"],
132
145
  async run(t) {
133
- // An app the computer has: the ui fixture where it is installed, else the phone's own Settings app. Listed;
134
- // launched, in front and shown; terminated, and no longer in front.
146
+ // An app the computer has: the ui fixture where it is installed, else a stock app (a Linux desktop's editor or
147
+ // terminal, the phone's own Settings app). Listed; launched, in front and shown; terminated, and no longer in front.
135
148
  const listed = await t.call("apps.list", {});
136
149
  t.assert(Array.isArray(listed.apps) && listed.apps.every((one) => typeof one?.id === "string"), `apps.list gives apps with ids: ${JSON.stringify(listed.apps).slice(0, 300)}`);
137
150
  const uiFixture = listed.apps.some((one) => one.id === UI_FIXTURE.id);
138
- const app = uiFixture ? UI_FIXTURE.id : settingsApp(t);
151
+ const app = uiFixture ? UI_FIXTURE.id : stockApp(t, listed.apps);
139
152
  t.assert(listed.apps.some((one) => one.id === app), `apps.list holds ${app}`);
140
153
  t.deepEqual(await t.call("apps.terminate", { id: app }), {}, `apps.terminate ${app}`);
141
154
  await t.until(async () => (await foreground(t)) !== app, `${app} not in front after apps.terminate`);
@@ -172,7 +185,7 @@ export const appsCases = [
172
185
  if (treeOff(t) !== undefined && featureOff(t.hello.features ?? {}, "ui.image") !== undefined)
173
186
  return t.skip("ui.observe has nothing to show on this computer: ui.tree and ui.image are both off");
174
187
  const listed = await t.call("apps.list", {});
175
- const app = listed.apps.some((one) => one.id === UI_FIXTURE.id) ? UI_FIXTURE.id : settingsApp(t);
188
+ const app = listed.apps.some((one) => one.id === UI_FIXTURE.id) ? UI_FIXTURE.id : stockApp(t, listed.apps);
176
189
  t.assert(listed.apps.some((one) => one.id === app), `apps.list holds ${app}`);
177
190
  t.deepEqual(await t.call("apps.terminate", { id: app }), {}, `apps.terminate ${app}`);
178
191
  await t.until(async () => (await foreground(t)) !== app, `${app} not in front after apps.terminate`);
@@ -1,8 +1,10 @@
1
1
  import type { ComputerClient } from "../../protocol.js";
2
2
  import type { Case, CaseContext } from "../types.js";
3
3
  /**
4
- * The path unix sockets a program of the computer's user may connect to: the computer's own, computerd's and the Archil
5
- * sync socket (which only syncs). A network namespace does not cut a path socket, so any other 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.
6
8
  */
7
9
  export declare const OWN_SOCKETS: readonly string[];
8
10
  /**
@@ -13,9 +15,24 @@ export declare const OUTSIDE_TARGETS: string[];
13
15
  /**
14
16
  * The isolation check, on the computer `client` reaches (the case's own by default): computerd's probe, run as the
15
17
  * computer's user, sees its own loopback alone, and is refused at the vendor's agent's declared ports on 127.0.0.1 and
16
- * ::1 and at OUTSIDE_TARGETS; and the path unix sockets it connects to (the probe's own listing, --sockets) are the
17
- * computer's own (OWN_SOCKETS, and a desktop's display) alone, each recorded with its type. A probe that reports no
18
- * socket 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.
18
+ * ::1 and at OUTSIDE_TARGETS; and the unix sockets it connects to, paths and abstract names (the probe's own listing,
19
+ * --sockets), are the computer's own (OWN_SOCKETS, and a desktop's display) alone, each recorded with its type; and every TCP and UDP
20
+ * listener in its own network is computerd's (assertOnlyComputerdListens: today, none listens). A probe that reports no
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.
19
22
  */
20
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>;
21
38
  export declare const isolationCases: Case[];
@@ -1,13 +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
- // (capabilities().vendorAgentPorts), and no outside address, and sees its own loopback alone: computerd init
3
- // --own-network at work.
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. 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 path unix sockets a program of the computer's user may connect to: the computer's own, computerd's and the Archil
8
- * sync socket (which only syncs). A network namespace does not cut a path socket, so any other 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.
9
12
  */
10
- 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];
11
14
  /**
12
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
13
16
  * through a resolver and a route its own network does not have.
@@ -16,9 +19,10 @@ export const OUTSIDE_TARGETS = ["1.1.1.1:443", "example.com:443"];
16
19
  /**
17
20
  * The isolation check, on the computer `client` reaches (the case's own by default): computerd's probe, run as the
18
21
  * computer's user, sees its own loopback alone, and is refused at the vendor's agent's declared ports on 127.0.0.1 and
19
- * ::1 and at OUTSIDE_TARGETS; and the path unix sockets it connects to (the probe's own listing, --sockets) are the
20
- * computer's own (OWN_SOCKETS, and a desktop's display) alone, each recorded with its type. A probe that reports no
21
- * socket 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.
22
+ * ::1 and at OUTSIDE_TARGETS; and the unix sockets it connects to, paths and abstract names (the probe's own listing,
23
+ * --sockets), are the computer's own (OWN_SOCKETS, and a desktop's display) alone, each recorded with its type; and every TCP and UDP
24
+ * listener in its own network is computerd's (assertOnlyComputerdListens: today, none listens). A probe that reports no
25
+ * 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.
22
26
  */
23
27
  export async function assertIsolated(t, client) {
24
28
  const ports = t.provider.capabilities().vendorAgentPorts ?? [];
@@ -52,27 +56,55 @@ export async function assertIsolated(t, client) {
52
56
  const what = agent.includes(target) ? "the vendor's agent" : "the outside";
53
57
  t.equal(result?.outcome, "refused", `a program of the computer's user, to ${what} at ${target} (${String(result?.detail ?? "no result")})`);
54
58
  }
55
- // The path unix sockets, which no network namespace cuts: computerd's own listing, so no image can lack it. Each with
56
- // the type that connected (stream, dgram, seqpacket); a search it could not finish proves nothing, and fails.
59
+ // The unix sockets: paths, which no network namespace cuts, and the abstract names of the user's own namespace.
60
+ // computerd's own listing, so no image can lack it. Each with the type that connected (stream, dgram, seqpacket); a
61
+ // search it could not finish proves nothing, and fails.
57
62
  const search = probe.sockets;
58
63
  if (search === null || typeof search !== "object" || !Array.isArray(search.sockets) || !Array.isArray(search.incomplete)) {
59
- return t.assert(false, "the probe reported no list of the path unix sockets a program can connect to (a computerd too old for probe --sockets), so the socket fence could not run");
64
+ return t.assert(false, "the probe reported no list of the unix sockets a program can connect to (a computerd too old for probe --sockets), so the socket fence could not run");
60
65
  }
61
66
  const found = search.sockets.map((one) => ({ path: String(one.path), type: String(one.type) }));
62
- t.observe(`path unix sockets a tool can connect to: ${found.map(({ path, type }) => `${path} (${type})`).join(", ") || "none"}`);
67
+ t.observe(`unix sockets a tool can connect to: ${found.map(({ path, type }) => `${path} (${type})`).join(", ") || "none"}`);
63
68
  const incomplete = search.incomplete.map(String);
64
69
  t.assert(incomplete.length === 0, `the probe could not search every place a socket may be, so the socket fence is unproven: ${incomplete.join("; ")}`);
65
- // A desktop's tools draw on its display: the one X socket of the display its hello names is the computer's own too.
70
+ // A desktop's tools draw on its display: the X server of the display its hello names, on its path and on the same
71
+ // name as an abstract one, is the computer's own too.
66
72
  const own = [...OWN_SOCKETS];
67
73
  if (t.provider.capabilities().kind === "desktop") {
68
74
  const display = await displaySocket(client ?? t.client);
69
75
  if (display !== undefined)
70
- own.push(display);
76
+ own.push(display, `@${display}`);
71
77
  else
72
78
  t.observe("the desktop's display socket: not known (its hello names no display of the form :N)");
73
79
  }
74
80
  const other = found.filter(({ path }) => !own.includes(path)).map(({ path, type }) => `${path} (${type})`);
75
- t.assert(other.length === 0, `a program of the computer's user connects to path unix sockets that are not the computer's own (${own.join(", ")}): ${other.join(", ")}`);
81
+ t.assert(other.length === 0, `a program of the computer's user connects to unix sockets that are not the computer's own (${own.join(", ")}): ${other.join(", ")}`);
82
+ assertOnlyComputerdListens(t, probe.listeners);
83
+ }
84
+ /**
85
+ * The TCP and UDP listeners in the network of the computer's user (the probe's listing, --sockets, from /proc/net/tcp,
86
+ * tcp6, udp and udp6 of its own namespace) are computerd's alone: each held by a process that runs computerd's own
87
+ * program, as the probe ties a socket's inode to the descriptors of the processes /proc shows it. Computerd listens on
88
+ * nothing there today: init's one TCP listener, the egress relay (--egress), is a Docker computer's, which takes no
89
+ * --own-network, and the Archil relay and sync server run as root beside the fence, in the vendor's network. So the rule
90
+ * now is that nothing listens. Init's own descriptors are not the probe's to read (it drops to the programs' uid
91
+ * non-dumpable), so a listener init opened there would fail here, named, until the probe ties it. A listing the probe did
92
+ * not report, or a table it could not read, fails in words.
93
+ */
94
+ function assertOnlyComputerdListens(t, reported) {
95
+ const search = reported;
96
+ if (search === null || typeof search !== "object" || !Array.isArray(search.listeners) || !Array.isArray(search.incomplete)) {
97
+ return t.assert(false, "the probe reported no list of the TCP and UDP listeners in the user's own network (a computerd too old for its listeners), so the listener fence could not run");
98
+ }
99
+ const listeners = search.listeners.map((one) => {
100
+ const { protocol, address, port, owner, computerd } = one;
101
+ return { protocol: String(protocol), address: String(address), port: String(port), owner: typeof owner === "string" && owner !== "" ? owner : "its owner not shown", computerd: computerd === true };
102
+ });
103
+ t.observe(`TCP and UDP listeners in the user's own network: ${listeners.map((one) => `${one.protocol} ${one.address} port ${one.port} (${one.owner}${one.computerd ? ", computerd" : ""})`).join(", ") || "none"}`);
104
+ const incomplete = search.incomplete.map(String);
105
+ t.assert(incomplete.length === 0, `the probe could not read every table of listeners, so the listener fence is unproven: ${incomplete.join("; ")}`);
106
+ const stray = listeners.filter((one) => !one.computerd).map((one) => `${one.protocol} port ${one.port} listens in the user's own network (on ${one.address}, ${one.owner}), and it isn't computerd's`);
107
+ t.assert(stray.length === 0, stray.join("; "));
76
108
  }
77
109
  /**
78
110
  * The X socket of the display a desktop's hello names (:N or :N.S, /tmp/.X11-unix/XN). Asked of the daemon itself: its
@@ -85,6 +117,46 @@ async function displaySocket(client) {
85
117
  const number = /^:(\d{1,4})(?:\.\d{1,4})?$/.exec(hello.value.display ?? "")?.[1];
86
118
  return number === undefined ? undefined : `/tmp/.X11-unix/X${number}`;
87
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
+ }
88
160
  export const isolationCases = [
89
161
  {
90
162
  id: "isolation.vendor-agent",
@@ -95,4 +167,13 @@ export const isolationCases = [
95
167
  await assertIsolated(t);
96
168
  },
97
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
+ },
98
179
  ];