@parcha/agentrun-computer 0.1.0-beta.67 → 0.1.0-beta.69

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 (83) hide show
  1. package/README.md +243 -9
  2. package/box/README.md +8 -0
  3. package/box/install.sh +60 -6
  4. package/dist/boxd.js +43 -8
  5. package/dist/computerd-linux-amd64 +0 -0
  6. package/dist/computerd-linux-arm64 +0 -0
  7. package/dist/computerd.json +1 -1
  8. package/dist/conformance/cli.d.ts +6 -0
  9. package/dist/conformance/cli.js +14 -3
  10. package/dist/conformance/instabox.d.ts +36 -0
  11. package/dist/conformance/instabox.js +43 -0
  12. package/dist/conformance/northflank.d.ts +44 -0
  13. package/dist/conformance/northflank.js +50 -0
  14. package/dist/conformance/sprites.d.ts +32 -0
  15. package/dist/conformance/sprites.js +40 -0
  16. package/dist/conformance/vercel.d.ts +35 -0
  17. package/dist/conformance/vercel.js +43 -0
  18. package/dist/descriptor.d.ts +6 -0
  19. package/dist/descriptor.js +2 -0
  20. package/dist/descriptors/agent37.d.ts +1 -0
  21. package/dist/descriptors/agent37.js +2 -0
  22. package/dist/descriptors/daytona.d.ts +1 -0
  23. package/dist/descriptors/daytona.js +2 -0
  24. package/dist/descriptors/e2b.d.ts +14 -0
  25. package/dist/descriptors/e2b.js +20 -3
  26. package/dist/descriptors/fly.d.ts +1 -0
  27. package/dist/descriptors/fly.js +2 -0
  28. package/dist/descriptors/groundbox.d.ts +1 -0
  29. package/dist/descriptors/groundbox.js +2 -0
  30. package/dist/descriptors/index.d.ts +106 -1
  31. package/dist/descriptors/index.js +8 -2
  32. package/dist/descriptors/instabox.d.ts +20 -0
  33. package/dist/descriptors/instabox.js +22 -0
  34. package/dist/descriptors/modal.d.ts +1 -0
  35. package/dist/descriptors/modal.js +2 -0
  36. package/dist/descriptors/northflank.d.ts +24 -0
  37. package/dist/descriptors/northflank.js +30 -0
  38. package/dist/descriptors/orgo.d.ts +1 -0
  39. package/dist/descriptors/orgo.js +2 -0
  40. package/dist/descriptors/render.d.ts +1 -0
  41. package/dist/descriptors/render.js +2 -0
  42. package/dist/descriptors/sprites.d.ts +19 -0
  43. package/dist/descriptors/sprites.js +19 -0
  44. package/dist/descriptors/vercel.d.ts +23 -0
  45. package/dist/descriptors/vercel.js +24 -0
  46. package/dist/docker/egress-main.js +17 -10
  47. package/dist/docker/egress-proxy.d.ts +7 -0
  48. package/dist/docker/egress-proxy.js +12 -0
  49. package/dist/docker/egress.d.ts +3 -1
  50. package/dist/docker/egress.js +11 -4
  51. package/dist/docker/image.d.ts +8 -2
  52. package/dist/docker/image.js +24 -3
  53. package/dist/docker.d.ts +6 -0
  54. package/dist/docker.js +15 -5
  55. package/dist/e2b.d.ts +25 -10
  56. package/dist/e2b.js +36 -16
  57. package/dist/groundbox.js +15 -2
  58. package/dist/hosted/download.d.ts +16 -0
  59. package/dist/hosted/download.js +108 -2
  60. package/dist/hosted/provider.js +25 -12
  61. package/dist/hosted/rest.js +23 -1
  62. package/dist/hosted/scripts.d.ts +2 -0
  63. package/dist/hosted/scripts.js +29 -0
  64. package/dist/hosted/ssh-exec.d.ts +17 -2
  65. package/dist/hosted/ssh-exec.js +17 -6
  66. package/dist/index.d.ts +2 -1
  67. package/dist/index.js +2 -1
  68. package/dist/instabox.d.ts +30 -0
  69. package/dist/instabox.js +424 -0
  70. package/dist/northflank.d.ts +44 -0
  71. package/dist/northflank.js +448 -0
  72. package/dist/orgo-desktop.js +2 -2
  73. package/dist/orgo-names.d.ts +15 -1
  74. package/dist/orgo-names.js +13 -0
  75. package/dist/orgo.d.ts +10 -0
  76. package/dist/orgo.js +64 -4
  77. package/dist/providers.d.ts +10 -4
  78. package/dist/render.js +4 -3
  79. package/dist/sprites.d.ts +37 -0
  80. package/dist/sprites.js +309 -0
  81. package/dist/vercel.d.ts +26 -0
  82. package/dist/vercel.js +262 -0
  83. package/package.json +22 -2
package/README.md CHANGED
@@ -16,7 +16,7 @@ import { checkMount, readBackOf, WORKSPACE, type MountSpec } from "@parcha/agent
16
16
 
17
17
  The package root holds the protocol, the registry and the descriptors, and loads no provider: a provider loads by its
18
18
  id (`providerFor(id, options)`, which imports that one provider's file), or from its subpath (`/docker`, `/daytona`,
19
- `/modal`, `/e2b`, `/orgo`, `/orgo-desktop`, `/phone-harness`, `/browserbase`, `/kernel`, `/local-chrome`, `/boxd`, `/smolcloud`, `/groundbox`). A provider's
19
+ `/modal`, `/e2b`, `/orgo`, `/orgo-desktop`, `/phone-harness`, `/browserbase`, `/kernel`, `/local-chrome`, `/boxd`, `/smolcloud`, `/groundbox`, `/vercel`, `/sprites`, `/instabox`, `/northflank`). A provider's
20
20
  option types (`DockerProviderOptions`, `ModalProviderOptions` and the like) come from its subpath too, not the root.
21
21
 
22
22
  The package carries the daemon for Linux amd64 and arm64 in `dist/`, so a provider runs it with no Go on the host. A
@@ -446,6 +446,7 @@ in the kernel's tool registry, keyed by these groups.
446
446
  | modal | none: `prepareImage()` answers the box image (`boxImageRef()`) |
447
447
  | e2b | none: `prepareImage()` answers the box template (`boxE2bTemplate()`), for a sandbox and a desktop alike |
448
448
  | smolcloud | none: `prepareImage()` answers the box image (`boxImageRef()`) |
449
+ | vercel | none: `prepareImage()` answers the box image's tag in the project's registry (`boxVercelImage()`) |
449
450
  | orgo | desktop: `ORGO_BASE_IMAGE` ("linux") |
450
451
  | phone-harness | phone: `PHONE_IMAGE` ("android") |
451
452
  | browserbase, kernel, local | browser: `BROWSER_IMAGE` ("chromium") |
@@ -455,7 +456,7 @@ in the kernel's tool registry, keyed by these groups.
455
456
  | docker | Docker | sandbox, desktop | none | bind | no |
456
457
  | daytona | Daytona | sandbox | `DAYTONA_API_KEY`; `DAYTONA_API_URL`, `DAYTONA_TARGET`, `DAYTONA_ARCHIL_EGRESS`, `DAYTONA_ATTACH_EGRESS`, `DAYTONA_LISTED_MS` (optional) | none (`unmounted`: archil); archil with `DAYTONA_ARCHIL_EGRESS` (`mountsWith`) | yes |
457
458
  | modal | Modal | sandbox | `MODAL_TOKEN_ID`, `MODAL_TOKEN_SECRET` | archil | yes |
458
- | e2b | E2B | sandbox, desktop | `E2B_API_KEY` | archil | yes |
459
+ | e2b | E2B | sandbox, desktop | `E2B_API_KEY`; `AGENTRUN_E2B_DOMAIN`, `AGENTRUN_E2B_API_URL`, `AGENTRUN_E2B_TEMPLATE` (optional) | archil | yes |
459
460
  | orgo | Orgo | desktop (Linux; Windows and macOS with `os`) | `ORGO_API_KEY` | none | yes |
460
461
  | phone-harness | Phone harness | phone | `PHONE_HARNESS_API_KEY` | none | yes |
461
462
  | browserbase | Browserbase | browser | `BROWSERBASE_API_KEY`, `BROWSERBASE_PROJECT_ID` | none | yes |
@@ -680,11 +681,17 @@ live under:
680
681
  | `AGENTRUN_BOX_APP` | Modal's `app` (serve's default, `agentrun`, when unset) |
681
682
  | `AGENTRUN_DOCKER_IMAGE` | Docker's `image` option, `{ image: <name> }` (unset: the provider's own recipe); `docker.image()` makes it ready and gives the tag a computer's spec names |
682
683
  | `E2B_API_KEY` | E2B's `apiKey`: serve's new name for the E2B box |
684
+ | `AGENTRUN_E2B_DOMAIN`, `AGENTRUN_E2B_API_URL` | E2B's `domain` and `apiUrl` (unset: `e2b.app`, and `https://api.<domain>`) |
685
+ | `AGENTRUN_E2B_TEMPLATE` | E2B's `template`, which its `prepareImage()` answers (unset: the box template); E2B's `imageEnv` too |
683
686
  | `BROWSERBASE_API_KEY`, `BROWSERBASE_PROJECT_ID` | Browserbase's `apiKey`, `projectId`: the names pi-browser reads today |
684
687
  | `KERNEL_API_KEY` | Kernel's `apiKey`: the name pi-browser reads today |
685
688
  | `BOXD_API_KEY`, `BOXD_ORG`, `BOXD_REGION` | boxd's `apiKey`, `org` and `region` (unset: the key's own org, the API's home region) |
686
689
  | `SMOLCLOUD_API_KEY` | smol cloud's `apiKey` |
687
690
  | `GROUNDBOX_API_KEY` | Groundbox's `apiKey` |
691
+ | `VERCEL_TOKEN`, `VERCEL_TEAM_ID`, `VERCEL_PROJECT_ID` | Vercel Sandbox's `token`, `teamId` and `projectId`, all required |
692
+ | `SPRITES_TOKEN` | Fly Sprites' `token`: the name Fly's own CLI reads |
693
+ | `INSTABOX_API_KEY` | InstaBox's `apiKey`: the name InstaBox's own CLI and SDK read |
694
+ | `NORTHFLANK_API_TOKEN`, `NORTHFLANK_COMPUTER_PROJECT_ID`, `NORTHFLANK_COMPUTER_TEAM_ID` | Northflank's `token` (the name Northflank's own client reads), `projectId` (required, no default) and `teamId` (an organisation token's alone) |
688
695
 
689
696
  - **the conformance CLI and the live harness** (`src/conformance/`: the CLI, each provider's conformance module and the
690
697
  sweeps) read their own `COMPUTER_<ID>_*` names, the ones the live scripts set, through each module's
@@ -853,7 +860,7 @@ key.
853
860
  package's own build, bound read-only with its `package.json`. It is on the provider's egress bridge alone (below),
854
861
  publishes no port, and runs as the computer's uid:gid with a read-only root, `--cap-drop ALL`, `no-new-privileges`, 256 MiB, 64
855
862
  pids, half a CPU (a fixed quota, not the computer's own cpus), 1024 open files and a bounded log. Its argv holds the list (or `--open public`), the computer's deadline (it ends itself then), this machine's own
856
- public addresses (refused as `this-host`), and `egress.hint`, the words a refusal adds (printable ASCII).
863
+ public addresses (refused as `this-host`), `egress.hint`, the words a refusal adds (printable ASCII), and `--max-tunnels` when `egress.maxTunnels` is set.
857
864
  `EGRESS_IMAGE` is the one place its digest is written. `create` pulls it at the first allow computer when the host
858
865
  lacks it (see Lifetime), so a host with no registry access pulls it ahead, reading the name from this package:
859
866
  `docker pull "$(node --input-type=module -e 'import { EGRESS_IMAGE } from "@parcha/agentrun-computer"; console.log(EGRESS_IMAGE)')"`
@@ -890,7 +897,9 @@ key.
890
897
  leaves the host; an IP literal outside a listed CIDR of its own family; any port but 80 and 443; a listed name or
891
898
  address that is private, loopback, link-local, metadata, multicast or reserved, in any form it is written (decimal,
892
899
  octal, hex, IPv4-mapped, NAT64, 6to4), or one of this machine's own; a Host header that names another host than the
893
- URI; SOCKS5 BIND and UDP ASSOCIATE; an HTTP upgrade; past 64 connections open at once or 20,000 in all. A name is
900
+ URI; SOCKS5 BIND and UDP ASSOCIATE; an HTTP upgrade; past its cap of connections open at once (64 unless
901
+ `egress.maxTunnels` sets a whole number from 1 to 256: the proxy's 1024 open files hold two per connection; anything
902
+ else is refused when the provider is made) or 20,000 in all; past the cap a new one is answered 429. A name is
894
903
  resolved once, every answer is checked, and the checked address is the one dialled, so rebinding a name between the
895
904
  check and the dial reaches nothing new; a redirect reaches the client as sent and is never followed. A log line holds
896
905
  the host, port, address and class, never a path, query or header. A refusal reads `403 <host> is not on this box's
@@ -918,7 +927,8 @@ key.
918
927
  deadline, runs while the computer runs, is hardened and bounded as above (its memory and swap, pids limit, private
919
928
  IPC and cgroup namespaces, and json-file log of 1m and 2 files included) with exactly its volume and code, and whose
920
929
  argv holds the list (or `--open public`) and refuses every one of the Docker host's own addresses the provider
921
- requires now (more is fine). Anything less is `{ other: "network allow, but its egress proxy ... <why>" }` (or
930
+ requires now (more is fine), and whose `--max-tunnels`, if any, is a cap create gives (1 to 256), whatever the cap is
931
+ set to now, so a changed setting leaves running proxies as they are. Anything less is `{ other: "network allow, but its egress proxy ... <why>" }` (or
922
932
  `network open, ...`). **A crashed proxy** is not
923
933
  restarted: the computer then reaches nothing, its network reads back `other` ("is not running"), and `attach` refuses
924
934
  it, so a caller makes a new computer. `list` reads every listed computer's proxy in one more inspect.
@@ -1068,7 +1078,9 @@ const made = await docker.create({ image: image.value, lifetimeMs: 600_000, netw
1068
1078
  built.
1069
1079
  - `DockerProvider`'s `image` option is that source; the default is `{ recipe: DOCKER_RECIPE }`, the provider's own
1070
1080
  image (`DEFAULT_DOCKER_IMAGE`): `python:3.12-slim` pinned by its index digest (`DOCKER_BASE`), with git, curl,
1071
- nodejs, npm, ripgrep and socat from apt. `docker.image({ signal?, timeoutMs?, onWait? })` is `ensureImage` of it with the
1081
+ xz-utils, ripgrep and socat from apt, and Node.js with its npm in `/usr/local` from the release's own tarball
1082
+ (`DOCKER_NODE_VERSION`, checked against `DOCKER_NODE_SHA256` for the host's architecture before it is unpacked), the
1083
+ release the box image and serve's own image run. `docker.image({ signal?, timeoutMs?, onWait? })` is `ensureImage` of it with the
1072
1084
  provider's docker CLI. A source that is neither throws at construction, in words.
1073
1085
  - **The docker CLI gets only what it reads.** The provider reads no environment: its `env` option is the host's (serve
1074
1086
  passes its own values of the docker descriptor's `hostEnv`), and every docker call it makes (`dockerArch`,
@@ -1972,13 +1984,47 @@ option, never the key. It reads no setting from the environment (see [Settings](
1972
1984
  `E2B_API_KEY`, and the conformance module the `COMPUTER_E2B_API_KEY` it reads, never `E2B_API_KEY`, whose value may be
1973
1985
  another team's on a shared host. The SDK reads `E2B_API_KEY`, `E2B_DOMAIN`, `E2B_API_URL` and `E2B_DEBUG` from
1974
1986
  `process.env` whenever it is not given them (`index.mjs:1140-1152`, `1177-1191`), so every call is given the key, the
1975
- domain (`options.domain`, default `e2b.app`), the API URL `https://api.<domain>` and `debug: false` explicitly: with
1987
+ domain (`options.domain`, default `e2b.app`), the API URL (`options.apiUrl`, default `https://api.<domain>`) and
1988
+ `debug: false` explicitly: with
1976
1989
  debug on, the SDK fakes a create and skips a kill (`index.mjs:5402`, `6021-6024`). The SDK also takes
1977
1990
  `E2B_SANDBOX_URL` when it is given no sandbox URL, and no option clears it (`index.mjs:1152`, `1183-1185`): it would
1978
1991
  send every call into a sandbox, the upload and the bridge with it, there. So the provider refuses to start while it is
1979
1992
  set in `process.env`: a read, and the library's one touch of E2B's environment. A unit test hands the provider's options
1980
1993
  to the real SDK's `ConnectionConfig` with all four ambient variables set, and reads back the provider's own.
1981
1994
 
1995
+ Every call is also given `httpVersion: "1.1"`, which wins over `E2B_HTTP_VERSION`: the SDK's undici client opens
1996
+ HTTP/2 otherwise, and when an idle HTTP/2 session times out it throws on a stream with no `error` listener, which ends
1997
+ the whole process. A unit test points the real SDK, given the provider's options, at a local server that prefers HTTP/2
1998
+ and reads HTTP/1.1 arriving.
1999
+
2000
+ ### Other clouds, and the operator's template
2001
+
2002
+ Three options, each filled by serve's setting of the same row (optional keys of E2B's descriptor, none a secret), point
2003
+ the provider at a cloud that speaks E2B's API, with the stock SDK, or at a template of the operator's own:
2004
+
2005
+ | option | serve's setting | what it is | unset |
2006
+ | --- | --- | --- | --- |
2007
+ | `domain` | `AGENTRUN_E2B_DOMAIN` | the cloud's domain: each sandbox's envd is under it, and so is the API unless `apiUrl` names another | `e2b.app` |
2008
+ | `apiUrl` | `AGENTRUN_E2B_API_URL` | the API's URL, for a cloud whose API is not `https://api.<domain>`: https, with no login, query or fragment, since the key goes to it; another is refused, naming the setting, before any call | `https://api.<domain>` |
2009
+ | `template` | `AGENTRUN_E2B_TEMPLATE` | the template `prepareImage()` answers, so every computer, sandbox or desktop, starts from it; E2B's descriptor names it as its `imageEnv` too, so serve takes an agent's `computer.image` that names it | the box template |
2010
+
2011
+ `apiKey` stays `E2B_API_KEY`, the key of whichever cloud the domain names. The SDK sends every call through one proxy,
2012
+ so it is given the process's proxy unless `NO_PROXY` exempts the whole domain and a given API URL's host too. The box
2013
+ template is public on E2B's own cloud alone; on another, a template of `box/Dockerfile` built on that cloud, named in
2014
+ `AGENTRUN_E2B_TEMPLATE`, is the one with Archil's client, which a Mode 2 folder mounts.
2015
+
2016
+ The clouds whose docs say they speak E2B's API, and what each needs. None of them is run live yet:
2017
+
2018
+ | cloud | settings | status |
2019
+ | --- | --- | --- |
2020
+ | Maritime | `AGENTRUN_E2B_DOMAIN=sb.mtm.sh` | not yet run live |
2021
+ | Orble | `AGENTRUN_E2B_DOMAIN=orble.tech`; it can't build templates, so `AGENTRUN_E2B_TEMPLATE` names one it has | not yet run live |
2022
+ | SUFY | `AGENTRUN_E2B_API_URL=https://us-south-1-sandbox.sufyapi.com` | not yet run live |
2023
+ | Alibaba Cloud Agent Sandbox | `AGENTRUN_E2B_DOMAIN=<region>.sandbox.aliyuncs.com` and `AGENTRUN_E2B_API_URL`, the API URL its docs give for the region | not yet run live |
2024
+ | PPIO | `AGENTRUN_E2B_DOMAIN=sandbox.ppio.cn`; its docs set `E2B_VALIDATE_API_KEY=false`, which e2b@2.63.0 never reads (it checks no key's form) | not yet run live |
2025
+ | UCloud | `AGENTRUN_E2B_DOMAIN=cn-wlcb.sandbox.ucloudai.com` | not yet run live |
2026
+ | Tencent Cloud Agent Runtime | `AGENTRUN_E2B_DOMAIN`, the endpoint its docs give | not yet run live |
2027
+
1982
2028
  ### How the daemon gets in, and how it is reached
1983
2029
 
1984
2030
  E2B's envd is the sandbox's first process, a systemd service with `Restart=always` (e2b-dev/infra
@@ -2979,8 +3025,9 @@ key's org has none, it builds it once, telling `onWait` "build" first:
2979
3025
  (a restore carries a snapshot's labels over to every machine made from it) and boxd's delete timer at 2 hours;
2980
3026
  2. the recipe as root through the image user's passwordless sudo: `mousepad` and `xfce4-terminal` from Ubuntu's
2981
3027
  universe, and `firefox-esr` from Mozilla's APT repository (Ubuntu 24.04's `firefox` is a snap, and a microVM runs no
2982
- snapd), its signing key held to a pinned sha256 before apt reads anything it signs; each program and its desktop
2983
- file (`org.xfce.mousepad`, `xfce4-terminal`, `firefox-esr`) checked;
3028
+ snapd), its signing key held to a pinned sha256 before apt reads anything it signs, and that origin pinned before
3029
+ its source is written: `firefox-esr*` at 500, every other package from it at -1, so it never replaces a distro
3030
+ package; each program and its desktop file (`org.xfce.mousepad`, `xfce4-terminal`, `firefox-esr`) checked;
2984
3031
  3. `snapshots.create` under the name, read until boxd says `ready`;
2985
3032
  4. the build machine deleted and read gone, pass, fail or cancel: the id create answered, read through `get` (a
2986
3033
  lagging list can't hide it), and any machine of its name in the org's list, so a create whose reply was lost is
@@ -3278,6 +3325,189 @@ minutes, past the hour any one connection may last: Groundbox closed its socket
3278
3325
  host attached again each time, the command's 1950 lines came back once each and in order, and a write made after the
3279
3326
  hour reached it. A command read across sockets dropped mid-output (close code 4000) also came back whole.
3280
3327
 
3328
+ ## Vercel Sandbox
3329
+
3330
+ ```ts
3331
+ import { providerFor } from "@parcha/agentrun-computer";
3332
+
3333
+ // The token is the caller's to pass (serve's VERCEL_TOKEN); the team and project ids are not secrets.
3334
+ const vercel = await providerFor("vercel", { token, teamId: "team_abc123", projectId: "prj_abc123" });
3335
+ const made = await vercel.create({ lifetimeMs: 600_000, network: "none" }, { requestId: "r1#3" });
3336
+ ```
3337
+
3338
+ A Vercel Sandbox computer is kind `linux`, a [Vercel Sandbox](https://vercel.com/docs/sandbox): a Firecracker microVM
3339
+ with its own kernel, root through `sudo`. With no image named, it starts from the box image as the project's Vercel
3340
+ Container Registry holds it, `agentrun-box:<recipe hash>`, the tag `prepareImage()` answers (`boxVercelImage()`). The
3341
+ operator pushes it once, from `box/`: `vercel vcr build docker . agentrun-box:<hash> --push`. A project without it
3342
+ refuses the create in words that give that command. Vercel runs on the shared machine-host adapter
3343
+ ([PROVIDERS.md](PROVIDERS.md)): `src/vercel.ts` is its `MachineHost`, over Vercel's REST API (`https://api.vercel.com`,
3344
+ `Authorization: Bearer <token>`, `?teamId=` on every call) with `fetch` and the shared REST client (no SDK).
3345
+
3346
+ | MachineHost | Vercel Sandbox |
3347
+ | --- | --- |
3348
+ | `create` | `POST /v3/sandboxes` named with the computer's name, the image, `persistent: false`, the lifetime as the session's `timeout`, `resources.vcpus` (2 unless the spec names a size), the packed labels as `tags`, and `networkPolicy: deny-all` where the computer needs no egress; a 409 is `exists` (unverified until the live run) |
3349
+ | `get` | `GET /v2/sandboxes/{name}?resume=false`, which never wakes one: `pending` is starting, `running` running, `stopping`, `stopped`, `snapshotting`, `failed` and `aborted` gone (with the session's `stopReason` as why); a 404 is none |
3350
+ | `list` | `GET /v2/sandboxes?project=&namePrefix=computer-`, with `tags=k:v` when one label is asked, every page |
3351
+ | `delete` | `DELETE /v2/sandboxes/{name}`; a 404 is done |
3352
+ | `exec` | a detached command (`POST /v2/sandboxes/sessions/{session}/cmd`, `sudo`, argv as its words, stdin attached), through `framedExec`: output from its NDJSON log stream (`GET .../cmd/{id}/logs`), stdin as base64 writes of 512 KiB by offset (`POST .../stdin`, safe to resend), `close` to end it, `POST .../kill` with signal 9 to kill it |
3353
+ | `extend` | `POST /v2/sandboxes/sessions/{session}/extend-timeout` by the difference from the end it reads; never earlier |
3354
+
3355
+ What Vercel refuses or this host works around:
3356
+
3357
+ - Tags are 5 at most, a value 256 characters at most, so the labels are packed into them (`facts.labels.packed`).
3358
+ - The log stream answers from the command's start each time it is read, so a stream that drops while the command runs
3359
+ is read again with the characters already given each stream skipped. A stream can also end before the command's
3360
+ last write, so once the command read finds it exited, the stream is read once more. An `error` line is the
3361
+ command's end in Vercel's words; ten failed reads in a row end it too.
3362
+ - Images come from Vercel Container Registry alone (`check()` refuses another registry's path), as `linux/amd64`
3363
+ builds, and Sandbox never runs an image's `ENTRYPOINT`. A create before the image is ready answers
3364
+ `image_not_ready`, read as `timeout`.
3365
+ - Sizes are 1 or an even 2 to 8 vCPUs, each with 2048 MiB; `check()` refuses any other, and any `memoryMb` but that.
3366
+ - A session lives 24 hours at most on Pro (45 minutes on Hobby); `extend` past the plan's cap is `limit`.
3367
+ - No Archil mount yet and no desktop.
3368
+
3369
+ Unverified until the live run: root makes a network namespace in the microVM (the fence for network none, open and a
3370
+ list); the log stream keeps a character written in two pieces whole and stays open through 75 s of silence; a create
3371
+ whose name the project holds answers 409; a sandbox's end is its session's start plus its timeout; no vendor agent
3372
+ listens on TCP in the VM.
3373
+
3374
+ ### Conformance on Vercel Sandbox
3375
+
3376
+ ```sh
3377
+ export COMPUTER_VERCEL_TOKEN=... COMPUTER_VERCEL_TEAM_ID=team_... COMPUTER_VERCEL_PROJECT_ID=prj_...
3378
+ before="$(mktemp -d)/before.json" # each run its own: --before refuses a file that is already there
3379
+ node packages/computer/dist/conformance/sweep.js --provider vercel --before "$before"
3380
+ AGENTRUN_COMPUTER_LIVE_VERCEL=1 npm run conformance -w @parcha/agentrun-computer -- --provider vercel --long \
3381
+ --run "$(node -p 'require(process.argv[1]).run' "$before")"
3382
+ node packages/computer/dist/conformance/sweep.js --provider vercel --after "$before"
3383
+ ```
3384
+
3385
+ The conformance module, `dist/conformance/vercel.js`, checks `AGENTRUN_COMPUTER_LIVE_VERCEL=1` first, then reads
3386
+ `COMPUTER_VERCEL_TOKEN` (`token`), `COMPUTER_VERCEL_TEAM_ID` (`teamId`) and `COMPUTER_VERCEL_PROJECT_ID`
3387
+ (`projectId`), all required, and `COMPUTER_VERCEL_IMAGE` (the run's image, default the box image), never
3388
+ `VERCEL_TOKEN`. Every computer of a run lives at most 30 minutes. The live sweep is the shared one; its scope is the
3389
+ project of the team. `test/vercel-provider.test.mjs` runs the host on a REST fake of the API, the exec pre-check
3390
+ included; no live run has been made yet.
3391
+
3392
+ ## Fly Sprites
3393
+
3394
+ ```ts
3395
+ import { providerFor } from "@parcha/agentrun-computer";
3396
+
3397
+ // The token is the caller's to pass (serve's SPRITES_TOKEN).
3398
+ const sprites = await providerFor("sprites", { token });
3399
+ const made = await sprites.create({ image: "default", lifetimeMs: 600_000, network: "none" }, { requestId: "r1#3" });
3400
+ ```
3401
+
3402
+ A Fly Sprites computer is a [sprite](https://docs.sprites.dev): a Firecracker microVM Fly keeps by name until it is
3403
+ deleted, from Fly's own Ubuntu image, the one image a sprite has (`"default"`). It is a sandbox alone: with no image to
3404
+ name, there is no desktop and no Archil mount. Sprites runs on the shared machine-host adapter
3405
+ ([PROVIDERS.md](PROVIDERS.md)): `src/sprites.ts` is its `MachineHost`, over the Sprites API
3406
+ (`https://api.sprites.dev`, `Authorization: Bearer <token>`) with `fetch`, the shared REST client and Node's
3407
+ `WebSocket` (no SDK).
3408
+
3409
+ | MachineHost | Fly Sprites |
3410
+ | --- | --- |
3411
+ | `create` | `POST /v1/sprites` with the request's name and the packed labels as `name=value` strings; the name is the id |
3412
+ | `get` | `GET /v1/sprites/{name}`: `running`, `warm` and `cold` are running (an exec wakes one asleep), any other status stopped; a 404 is none |
3413
+ | `list` | `GET /v1/sprites?prefix=computer-`, every page, then the asked labels kept here (Fly filters by none) |
3414
+ | `delete` | `DELETE /v1/sprites/{name}`, a 404 done |
3415
+ | `exec` | the exec WebSocket (`/v1/sprites/{name}/exec`, argv as its `cmd` words, `stdin=true`, `max_run_after_disconnect=10s`) through `framedExec`: stdin as `0x00` frames and its end as `0x04`, stdout `0x01`, stderr `0x02`, the exit `0x03`; `kill` is `POST .../exec/{session}/kill?signal=SIGKILL`, by the id the socket's `session_info` names |
3416
+
3417
+ No `upload` (the adapter sends the daemon through exec's stdin) and no `extend` (the janitor moves the deadline label).
3418
+ The size and the image are Fly's: `check()` refuses `cpus`, `memoryMb` and any image but `"default"`. A sprite lives
3419
+ until deleted, so its lifetime is the janitor's, 30 days at most. A create rate cap (`sprite_creation_rate_limited`) or
3420
+ a concurrency cap (`concurrent_sprite_limit_exceeded`) is a `limit`.
3421
+
3422
+ Unverified until the live run: the arch (amd64); a label string's room (64 bytes); a taken name answering 409; the exec
3423
+ user being root or having passwordless sudo, and root making a network namespace; no vendor agent on TCP; the exec
3424
+ socket holding 75 s of silence with no ping; and a sprite with an exec running never going to sleep.
3425
+
3426
+ ## InstaBox
3427
+
3428
+ ```ts
3429
+ import { providerFor } from "@parcha/agentrun-computer";
3430
+
3431
+ // The key is the caller's to pass (serve's INSTABOX_API_KEY).
3432
+ const instabox = await providerFor("instabox", { apiKey });
3433
+ const made = await instabox.create({ image: "minimal", lifetimeMs: 600_000, network: "none" }, { requestId: "r1#3" });
3434
+ ```
3435
+
3436
+ An InstaBox computer is an [InstaBox](https://instabox.sh/llms-full.txt) machine: a Firecracker microVM from one of
3437
+ InstaBox's templates (`"minimal"` by default, or `agent-browser`, `universal`) or a snapshot of the key's workspace, by
3438
+ name or `sn_` id. It is a sandbox alone: a create names no image of ours, so there is no desktop and no Archil mount.
3439
+ InstaBox runs on the shared machine-host adapter ([PROVIDERS.md](PROVIDERS.md)): `src/instabox.ts` is its
3440
+ `MachineHost`, over the InstaBox API (`https://api.instabox.sh`, `X-API-Key: <key>`) with `fetch` and the shared REST
3441
+ client, and over SSH with the host's `ssh2` package, as Agent37 and Morph (no SDK). A computer needs a paid plan: it
3442
+ switches off InstaBox's idle pause and maximum run, which the free plan refuses (a 403 `spec_not_allowed`, a `refused`
3443
+ in those words).
3444
+
3445
+ | MachineHost | InstaBox |
3446
+ | --- | --- |
3447
+ | `create` | `POST /v1/machines` under an `Idempotency-Key` of the request, with its name, the template (`templateId`) or snapshot (`snapshotId`), the size, the packed labels as `metadata`, `deleteAfterSeconds` at the backstop, `autoSuspendAfterSeconds: 0`, `maxRunMinutes: -1`, no vault and no secrets; the answer's `machineId` is the id |
3448
+ | `get` | `GET /v1/machines/{id}`: creating, starting and resuming are starting, running is running once `runtime.ready`, stopping, stopped, suspending and suspended are stopped, deleting and error gone (error in its `lastError` words); a 404 or a `deleted` record is none |
3449
+ | `list` | `GET /v1/machines?metadata=<name>:<value>`, every page, then the asked labels kept here and a `deleted` record left out |
3450
+ | `delete` | `DELETE /v1/machines/{id}` with `X-Confirm-Delete: <id>` and a fresh `Idempotency-Key`, a 404 done, a `409 operation_conflict` sent again within the call's bound; then the machine's SSH connections end |
3451
+ | `exec` | SSH through InstaBox's gateway with `SshExec`, logged in as a token from `POST /v1/machines/{id}/ssh-tokens` (the username, SSH's none auth), the gateway's host key pinned to the token's `hostKeyFingerprint`, which is required: a token answer with none, or one not `SHA256:` and 43 characters of unpadded base64, is refused before any connection, so the token never leaves; the machine's user, `user`, with passwordless sudo; a held token the gateway refuses is let go and another minted, once, and execs refused on the same token share its replacement; the mint is shared by the execs that ask at once and stopped by none of them, each waiting on it within its own time and signal |
3452
+
3453
+ No `upload` (InstaBox's file API writes as the machine's user, not root, so the adapter sends the daemon through exec's
3454
+ stdin) and no `extend` (the janitor moves the deadline label). `check()` takes a template id or a snapshot's name or
3455
+ id, and the sizes InstaBox offers: 2, 4, 8, 16 or 32 vCPUs with 2048 MB each, one alone taking the other's match. A
3456
+ rate, quota, concurrency or capacity cap (`rate_limited`, `quota_exceeded`, `concurrency_limit`, `no_capacity`,
3457
+ `machine_cooldown`) is a `limit`; `missing_scope` and `permission_denied` are `denied`. The daemon user can't be uid
3458
+ 1000, the machine user's.
3459
+
3460
+ Unverified until the live run: the gateway taking the token as the username with SSH's none auth; its host key being one
3461
+ ssh2 verifies, whose sha256 is `hostKeyFingerprint`; a taken name answering 409; a deleted machine reading 404 or a
3462
+ `deleted` record; sshd's port 22 being the one vendor listener; `minimal` being on every paid plan; the 8 KiB metadata
3463
+ bound counting compact JSON; a silent SSH channel holding 75 s; and root making a network namespace.
3464
+
3465
+ ## Northflank
3466
+
3467
+ ```ts
3468
+ import { providerFor } from "@parcha/agentrun-computer";
3469
+
3470
+ // The token and the project are the caller's to pass (serve's NORTHFLANK_API_TOKEN and NORTHFLANK_COMPUTER_PROJECT_ID).
3471
+ const northflank = await providerFor("northflank", { token, projectId });
3472
+ const image = await northflank.prepareImage();
3473
+ const made = await northflank.create({ image: image.value, lifetimeMs: 600_000, network: "none" }, { requestId: "r1#3" });
3474
+ ```
3475
+
3476
+ A Northflank computer is a [Northflank sandbox](https://northflank.com/docs/v1/application/sandboxes): a service in your
3477
+ own project, on Northflank's cloud a Kata microVM, from the box image's public tag (`prepareImage()`, no call) or the
3478
+ spec's image, its command `sleep infinity`. The project is required and has no default; `teamId` is for an organisation
3479
+ token alone. It is a sandbox alone for now: no desktop and no Archil mount. Northflank runs on the shared machine-host
3480
+ adapter ([PROVIDERS.md](PROVIDERS.md)): `src/northflank.ts` is its `MachineHost`, over the Northflank API
3481
+ (`https://api.northflank.com/v1`, `Authorization: Bearer <token>`) with `fetch`, the shared REST client and Node's
3482
+ `WebSocket` (no SDK).
3483
+
3484
+ | MachineHost | Northflank |
3485
+ | --- | --- |
3486
+ | `create` | `POST .../projects/{project}/services/deployment` with the request's name, the plan of its size, the image as `external.imagePath` under `/bin/sh -c 'exec sleep infinity'`, one instance, the packed labels as the workload's annotations and `createOptions.expiryTime` at the backstop (300 s to 7 days); then `POST .../services/{name}/scale` to one instance; the name is the id. A scale that fails deletes the service before create answers, and where that delete fails too create answers `vendor`, so the adapter sweeps the name |
3487
+ | `get` | `GET .../services/{id}`: `PENDING` and `IN_PROGRESS` are starting, `COMPLETED` running; `FAILED`, one past its expiry (`expiredAt`) or one in a status it doesn't know is stopped, with the reason, so it stays listed and the janitor deletes it; a 404 is none |
3488
+ | `list` | `GET .../services`, every page, the `computer-` services kept (and the asked name alone when one is asked), each read by `get` for its annotations, which the listing lacks. That read answers the adapter's own read of each listed computer once, within 2 s, so a sweep reads each computer once; a create or delete drops it |
3489
+ | `delete` | `DELETE .../services/{id}`, a 404 done |
3490
+ | `exec` | the command-exec WebSocket (`wss://api.northflank.com/v1/command-exec/projects/{project}/services/{id}`) through `framedExec`: an `init` message with the token and argv (no shell, root, `latin1`, no tty), stdin as `payload` messages and its end as `stdInEnd`, `stdOut` and `stdErr` bytes as latin1 strings, the exit from `completion` once the socket closes or 30 s after the last output; `kill` is the shared pid wrapper's, Northflank having none |
3491
+
3492
+ An organisation token's paths start `/v1/teams/{team}/projects/...`. No `upload` and no `extend` (the janitor moves the
3493
+ deadline label, 7 days at most; past the backstop Northflank pauses the service and schedules its deletion). `check()`
3494
+ takes a registry image reference and the plans' sizes: 1 vCPU with 2048 MB, 2 with 4096, 4 with 8192, 8 with 16384, one
3495
+ alone taking the other's match. The adapter reads status every 2 s, since a token has 1000 requests an hour. A 409 on
3496
+ create is `exists`; a 429 a `limit`.
3497
+
3498
+ The conformance module, `dist/conformance/northflank.js`, checks `AGENTRUN_COMPUTER_LIVE_NORTHFLANK=1` first, then reads
3499
+ `COMPUTER_NORTHFLANK_TOKEN` (`token`) and `COMPUTER_NORTHFLANK_PROJECT_ID` (`projectId`), both required, and
3500
+ `COMPUTER_NORTHFLANK_TEAM_ID`, `COMPUTER_NORTHFLANK_API_URL`, `COMPUTER_NORTHFLANK_DAEMON` and
3501
+ `COMPUTER_NORTHFLANK_IMAGE` (the run's image, default the box image), never `NORTHFLANK_API_TOKEN`, `NF_API_TOKEN`,
3502
+ `NF_PROJECT_ID` (which Northflank injects into its own services) or `NORTHFLANK_PROJECT_ID`. Every computer of a run
3503
+ lives at most 30 minutes.
3504
+
3505
+ Unverified until the live run: latin1 carrying every byte both ways; the exec socket holding 75 s of silence with no
3506
+ ping; output trailing the `completion` message, and the socket closing after it; the exec user root being root; a taken
3507
+ name answering 409; a service's id being its name; the annotations read back on `get` as given; the quickstart's scale
3508
+ call after create being needed or harmless; a deleted service answering 404; amd64, with no vendor agent on TCP; and
3509
+ root making a network namespace.
3510
+
3281
3511
  ## Conformance
3282
3512
 
3283
3513
  A provider for another vendor passes the same suite as Docker's, with one command. The suite is data: each case in
@@ -3382,6 +3612,10 @@ provider, or a conformance module's:
3382
3612
  folder on the host for a bind, the disk's file API for Archil. `undefined` for a kind it cannot make. The runner
3383
3613
  closes each folder when its case ends. `--provider docker` gives a bind of a new folder under the temp directory,
3384
3614
  owned by the provider's user. Without this export the mount cases skip in words.
3615
+ - `export const conformanceClock`, for a host whose timers run on a clock of its own (a fake host's): `{ now(), sleep(ms) }`,
3616
+ the run's clock, which the deadline case reads and waits on, so a 45 s lifetime is waited out on it rather than in
3617
+ real time. It reads no earlier than the clock the provider stamps a deadline with. A vendor's module exports none:
3618
+ its run waits on the wall clock. `packages/serve/scripts/dial-conformance.mjs` takes it the same way.
3385
3619
 
3386
3620
  Core and Full follow the Kubernetes agent-sandbox conformance levels (KEP-539.2):
3387
3621
 
package/box/README.md CHANGED
@@ -10,6 +10,14 @@ Every step of the build is `install.sh`, POSIX shell run as root on the Dockerfi
10
10
  account from a running machine (a snapshot, a blueprint, a template) boots that base, copies both files into one folder,
11
11
  runs `sh install.sh` as root and snapshots the result. A second run on the same machine ends the same.
12
12
 
13
+ A vendor whose base is Ubuntu 24.04 runs the same `install.sh`. Ubuntu has no `firefox-esr` (its `firefox` is a snap),
14
+ so where `apt-cache policy firefox-esr` reads no candidate, the desktop step adds Mozilla's APT repository first: its
15
+ signing key fetched over https and refused unless the file holds that one key, fingerprint
16
+ `35BAA0B33E9EB396F59CA838C0BA5CE6DC6315A3`; a pin in `/etc/apt/preferences.d/mozilla` that lets
17
+ `packages.mozilla.org` supply `firefox-esr` and its `firefox-esr-*` packages and puts everything else from it at -1,
18
+ so it never replaces a package of the base's; and the source, signed by that key alone. A base whose apt has
19
+ `firefox-esr` (Debian's) keeps its own package and never reaches Mozilla.
20
+
13
21
  The image also serves a vendor that boots it with env but has no exec stream into it: the machine dials the server
14
22
  (`spec/computer/attach.md`). `install.sh` writes `agentrun-dial` to `/usr/local/bin`, root's, 0755, and the
15
23
  Dockerfile's `CMD` runs it when the provider's create set `AGENTRUN_ATTACH_URL`, and `sleep infinity` otherwise, so
package/box/install.sh CHANGED
@@ -9,7 +9,9 @@
9
9
  # sh install.sh checked the last step alone: any sudo taken away, then every check. recipe.mjs's onImage runs it on
10
10
  # the published image, after E2B's template builder has added sudo there.
11
11
  #
12
- # It reads the network only through apt (Debian's mirrors) and for Archil's package. Run twice on one machine it ends the
12
+ # It reads the network only through apt (the base's mirrors), for Archil's package and for Node's release, the two checked
13
+ # by sha256, and, on a base whose apt has no firefox-esr (Ubuntu 24.04, whose firefox is a snap), for Mozilla's APT
14
+ # repository, its key checked by fingerprint (mozilla_apt). Run twice on one machine it ends the
13
15
  # same, for a vendor's snapshot flow may retry it: each step that makes something looks for it first.
14
16
  set -eu
15
17
 
@@ -17,41 +19,91 @@ set -eu
17
19
  ARCHIL_VERSION=0.10.1-1793222256
18
20
  ARCHIL_SHA256_AMD64=f219e70287e8152f3f0c7222e1c3319f4665897235af7c33a8846e56a5a5786a
19
21
  ARCHIL_SHA256_ARM64=10ed430e51c268af095dd9e6c7aa6cdbb951d2430d62a76458719db168f40c0e
22
+ # The Node release the server's image runs (packages/serve/docker/Dockerfile), for the agent's node, npm and npx: Debian's
23
+ # nodejs comes with npm 9, older than the npm current packages are published for. The sums are the release's signed
24
+ # SHASUMS256.txt lines, checked against the signer that Dockerfile pins.
25
+ NODE_VERSION=24.22.3
26
+ NODE_SHA256_AMD64=4f2b175a6d53a5c617a80dba2676238a0688cef28c6da4eba35c7d844e66fcfb
27
+ NODE_SHA256_ARM64=6e51a2ada00f0011cc266f65d98922b403d7ad88f809ca2aa615a5fe1ce6e86c
20
28
  # Where the provider runs the root helper from.
21
29
  HELPER=/usr/local/sbin/agentrun-archil
22
30
  # The entrypoint of a machine that dials the server (dial below).
23
31
  DIAL=/usr/local/bin/agentrun-dial
32
+ # Mozilla's APT repository, for firefox-esr where the base's apt has none (mozilla_apt below): the fingerprint of its
33
+ # signing key as Mozilla publishes it, where the key is kept, apt's pin for the repository, and the source signed by it.
34
+ MOZILLA_FPR=35BAA0B33E9EB396F59CA838C0BA5CE6DC6315A3
35
+ MOZILLA_KEY=/etc/apt/keyrings/packages.mozilla.org.asc
36
+ MOZILLA_PIN=/etc/apt/preferences.d/mozilla
37
+ MOZILLA_LIST=/etc/apt/sources.list.d/mozilla.list
24
38
 
25
39
  here=$(dirname "$0")
26
40
 
27
- # A coding agent's tools, FUSE, nftables and the archil client (checked by sha256), the tool user, and /workspace.
41
+ # A coding agent's tools, Node, FUSE, nftables and the archil client (Node and archil checked by sha256), the tool user,
42
+ # and /workspace.
28
43
  packages() {
29
44
  arch="$(dpkg --print-architecture)"
30
45
  case "$arch" in
31
- amd64) sum="$ARCHIL_SHA256_AMD64" ;;
32
- arm64) sum="$ARCHIL_SHA256_ARM64" ;;
46
+ amd64) sum="$ARCHIL_SHA256_AMD64"; node_arch=x64; node_sum="$NODE_SHA256_AMD64" ;;
47
+ arm64) sum="$ARCHIL_SHA256_ARM64"; node_arch=arm64; node_sum="$NODE_SHA256_ARM64" ;;
33
48
  *) echo "no archil client for $arch" >&2; exit 1 ;;
34
49
  esac
35
50
  case "$sum" in unpinned) echo "archil ${ARCHIL_VERSION} for $arch has no pinned sha256 yet: set ARCHIL_SHA256_$(echo "$arch" | tr a-z A-Z) to the package's sum" >&2; exit 1 ;; esac
36
51
  apt-get update -qq
37
52
  DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends \
38
- git curl ca-certificates nodejs npm ripgrep fuse3 nftables >/dev/null
53
+ git curl ca-certificates xz-utils ripgrep fuse3 nftables >/dev/null
54
+ if [ "$(/usr/local/bin/node --version 2>/dev/null)" != "v$NODE_VERSION" ]; then
55
+ curl -fsSL -o /tmp/node.tar.xz "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${node_arch}.tar.xz"
56
+ echo "$node_sum /tmp/node.tar.xz" | sha256sum -c -
57
+ tar -xJf /tmp/node.tar.xz -C /usr/local --strip-components=1 --no-same-owner
58
+ rm -f /usr/local/CHANGELOG.md /usr/local/README.md /usr/local/LICENSE
59
+ fi
39
60
  if [ "$(dpkg-query -W -f '${Version}' archil 2>/dev/null)" != "$ARCHIL_VERSION" ]; then
40
61
  curl -fsSL -o /tmp/archil.deb "https://s3.amazonaws.com/archil-client/pkg/archil_${ARCHIL_VERSION}_${arch}.deb"
41
62
  echo "$sum /tmp/archil.deb" | sha256sum -c -
42
63
  DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends /tmp/archil.deb >/dev/null
43
64
  fi
44
- rm -rf /var/lib/apt/lists/* /tmp/archil.deb
65
+ rm -rf /var/lib/apt/lists/* /tmp/archil.deb /tmp/node.tar.xz
45
66
  getent group agentrun-tool >/dev/null || groupadd --gid 2510 agentrun-tool
46
67
  id -u agentrun-tool >/dev/null 2>&1 || useradd --uid 2510 --gid 2510 --no-create-home --home-dir /tmp --shell /bin/sh agentrun-tool
47
68
  install -d -o root -g root -m 0755 /workspace
48
69
  }
49
70
 
71
+ # firefox-esr's source where the base's apt has none: Ubuntu 24.04 has no firefox-esr, and its firefox is a snap, which
72
+ # no image here runs. The test is apt's own: `apt-cache policy firefox-esr` in the C locale (its words are translated
73
+ # otherwise) reads no candidate, or nothing for a name apt never heard of. A base whose apt has one (Debian's) keeps it,
74
+ # and nothing below runs. Else Mozilla's key is fetched over https alone and read with gpg (installed for this alone,
75
+ # never imported into a keyring): the file must hold one key, MOZILLA_FPR, for apt trusts every key in a signed-by file.
76
+ # The pin is written before the source, so apt never reads the source unpinned: packages.mozilla.org supplies
77
+ # firefox-esr and its own firefox-esr-* packages and nothing else (-1 is never installed), so this source can never
78
+ # replace a package of the base's. A second run finds the candidate this one added, and runs nothing.
79
+ mozilla_apt() {
80
+ case "$(LC_ALL=C apt-cache policy firefox-esr | awk '$1 == "Candidate:" { print $2 }')" in
81
+ "" | "(none)") ;;
82
+ *) return 0 ;;
83
+ esac
84
+ DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends gnupg >/dev/null
85
+ install -d -m 0755 "${MOZILLA_KEY%/*}"
86
+ curl -fsSL --proto =https -o "$MOZILLA_KEY" https://packages.mozilla.org/apt/repo-signing-key.gpg
87
+ home=$(mktemp -d)
88
+ fpr=$(gpg --homedir "$home" --quiet --show-keys --with-colons "$MOZILLA_KEY" | awk -F: '$1 == "pub" { pub = 1; next } $1 == "fpr" && pub { print $10; pub = 0 }' | tr '\n' ' ')
89
+ rm -rf "$home"
90
+ fpr=${fpr% }
91
+ if [ "$fpr" != "$MOZILLA_FPR" ]; then
92
+ rm -f "$MOZILLA_KEY"
93
+ echo "the APT signing key from packages.mozilla.org has the fingerprint ${fpr:-(none: gpg read no key)}, not Mozilla's published $MOZILLA_FPR: apt is given nothing from packages.mozilla.org" >&2
94
+ exit 1
95
+ fi
96
+ printf 'Package: firefox-esr*\nPin: origin packages.mozilla.org\nPin-Priority: 500\n\nPackage: *\nPin: origin packages.mozilla.org\nPin-Priority: -1\n' >"$MOZILLA_PIN"
97
+ echo "deb [signed-by=$MOZILLA_KEY] https://packages.mozilla.org/apt mozilla main" >"$MOZILLA_LIST"
98
+ apt-get update -qq
99
+ }
100
+
50
101
  # The desktop: Xvfb and xfwm4, which the provider starts through computerd as the tool user on :0, and the apps an agent
51
102
  # opens. Each program and each app's desktop file is checked here. It comes before the last step, so a package that
52
103
  # brought sudo is taken away and checked gone there (a check here would refuse E2B's build, whose builder adds sudo first).
53
104
  desktop() {
54
105
  apt-get update -qq
106
+ mozilla_apt
55
107
  DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends \
56
108
  xvfb xfwm4 x11-xserver-utils xfce4-terminal mousepad firefox-esr thunar xdotool fonts-dejavu-core adwaita-icon-theme >/dev/null
57
109
  rm -rf /var/lib/apt/lists/*
@@ -211,6 +263,8 @@ checked() {
211
263
  [ ! -e /etc/sudoers ] && [ ! -e /etc/sudoers.d ] || { echo "the image has a sudoers file" >&2; exit 1; }
212
264
  ids="$(id -u agentrun-tool):$(id -g agentrun-tool)"
213
265
  [ "$ids" = "2510:2510" ] || { echo "agentrun-tool is $ids" >&2; exit 1; }
266
+ [ "$(/usr/local/bin/node --version)" = "v$NODE_VERSION" ] || { echo "the image's node is not $NODE_VERSION" >&2; exit 1; }
267
+ for x in npm npx; do [ -x "/usr/local/bin/$x" ] || { echo "the image has no $x beside node" >&2; exit 1; }; done
214
268
  archil --version | head -1
215
269
  }
216
270
 
package/dist/boxd.js CHANGED
@@ -7,7 +7,7 @@ import { createHash, randomBytes } from "node:crypto";
7
7
  import { BOXD, BOXD_DEFAULT_IMAGE } from "./descriptors/boxd.js";
8
8
  import { DEADLINE_LABEL, show } from "./drift.js";
9
9
  import { HostError } from "./host.js";
10
- import { CALL_SLACK_MS, codeOfError, orThrow, race, runChecked, until } from "./hosted/process.js";
10
+ import { CALL_SLACK_MS, codeOfError, orThrow, pause, race, runChecked, until } from "./hosted/process.js";
11
11
  import { HostedProvider, mayHaveMade } from "./hosted/provider.js";
12
12
  import { httpsBase } from "./hosted/rest.js";
13
13
  import { shellLine } from "./hosted/scripts.js";
@@ -50,9 +50,11 @@ const MOZILLA_KEY_SHA256 = "3ecc63922b7795eb23fdc449ff9396f9114cb3cf186d6f5b53ad
50
50
  * What a desktop needs that boxd's own image lacks (Xvfb, xdotool and Thunar are the image's already): Xfce's text
51
51
  * editor and terminal (mousepad and xfce4-terminal, from Ubuntu's universe) and Firefox ESR, from Mozilla's APT
52
52
  * repository, since Ubuntu 24.04's firefox is a snap and a microVM runs no snapd. Mozilla's key is held to its sha256
53
- * before apt reads anything it signs. Each program and desktop file is checked. Run as root on a build machine of boxd's
54
- * own image, with no single quote in it (it goes in one pair). The snapshot's name carries this recipe's hash, so a
55
- * new recipe is a new snapshot.
53
+ * before apt reads anything it signs. That origin is pinned before its source is written, so apt never reads it
54
+ * unpinned: firefox-esr and its own firefox-esr-* packages at 500, every other package from it at -1 (never installed),
55
+ * so it can never replace or downgrade a distro package. Each program and desktop file is checked. Run as root on a
56
+ * build machine of boxd's own image, with no single quote in it (it goes in one pair). The snapshot's name carries this
57
+ * recipe's hash, so a new recipe is a new snapshot.
56
58
  */
57
59
  const DESKTOP_RECIPE = [
58
60
  "set -e",
@@ -62,8 +64,8 @@ const DESKTOP_RECIPE = [
62
64
  "install -d -m 0755 /etc/apt/keyrings",
63
65
  `curl -fsSL https://packages.mozilla.org/apt/repo-signing-key.gpg -o ${MOZILLA_KEY}`,
64
66
  `echo "${MOZILLA_KEY_SHA256} ${MOZILLA_KEY}" | sha256sum -c --quiet - || { echo "the APT signing key from packages.mozilla.org is not the one this recipe pins" >&2; exit 1; }`,
67
+ 'printf "Package: firefox-esr*\\nPin: origin packages.mozilla.org\\nPin-Priority: 500\\n\\nPackage: *\\nPin: origin packages.mozilla.org\\nPin-Priority: -1\\n" > /etc/apt/preferences.d/mozilla',
65
68
  `echo "deb [signed-by=${MOZILLA_KEY}] https://packages.mozilla.org/apt mozilla main" > /etc/apt/sources.list.d/mozilla.list`,
66
- 'printf "Package: *\\nPin: origin packages.mozilla.org\\nPin-Priority: 1000\\n" > /etc/apt/preferences.d/mozilla',
67
69
  "apt-get update -qq",
68
70
  "apt-get install -y -qq --no-install-recommends mousepad xfce4-terminal firefox-esr >/dev/null",
69
71
  'for x in mousepad xfce4-terminal firefox-esr; do command -v "$x" >/dev/null || { echo "the desktop has no $x" >&2; exit 1; }; done',
@@ -79,6 +81,8 @@ const BUILD_TTL_S = 2 * 60 * 60;
79
81
  const BUILD_POLL_MS = 2_000;
80
82
  /** The most a build machine's cleanup waits for it to read gone. */
81
83
  const GONE_MS = 120_000;
84
+ /** The pause before a wait for a machine boxd read not found just after its create, as the SDK's own wait polls. */
85
+ const NOT_YET_MS = 500;
82
86
  /** The error with words added to its message (one that cannot be written stays as it was): the error is what the caller gets. */
83
87
  function withWords(error, words) {
84
88
  if (error instanceof Error) {
@@ -133,7 +137,8 @@ class BoxdHost {
133
137
  /**
134
138
  * An isolated machine (on none of the org's networks) with no standby, which would freeze a quiet computer. Once it is
135
139
  * ready: nothing out (the allowlist ["none"]) and no hibernation, since boxd's idle timers watch traffic and a computer
136
- * may have none. A step after the machine exists that throws an error the adapter reads as a create that may have made
140
+ * may have none. A not found while boxd comes to read the new machine is waited past (#ready). A step after the
141
+ * machine exists that throws an error the adapter reads as a create that may have made
137
142
  * one (mayHaveMade: vendor, timeout) is the adapter's to clean up: it sweeps the request's name, finds this machine and
138
143
  * deletes it (a timeout's once this call settles). Deleted here first, the sweep would find none and keep listing, and
139
144
  * delete a second create's machine of the same request instead. A refusal (limit, denied, ...) the adapter reads as a
@@ -155,7 +160,7 @@ class BoxdHost {
155
160
  deleteAfter: Math.ceil((Date.parse(req.backstopAt) - Date.now()) / 1000),
156
161
  });
157
162
  try {
158
- await this.machines.waitUntilReady(made.id, { timeout: ctx.timeoutMs });
163
+ await this.#ready(made.id, ctx.timeoutMs, ctx.signal);
159
164
  await this.machines.setEgressAllow(made.id, ["none"]);
160
165
  await this.machines.setAutoHibernateTimeout(made.id, 0);
161
166
  }
@@ -166,6 +171,36 @@ class BoxdHost {
166
171
  }
167
172
  return { id: made.id };
168
173
  }
174
+ /**
175
+ * waitUntilReady on a machine create just answered with, within ms, through boxd's not found: boxd can read such a
176
+ * machine as not found for a moment (live creates read "VM not found" about a second in, and a delete by id right
177
+ * after read not found too while the machine was there), so a not found is waited past, NOT_YET_MS apart. One still
178
+ * not found when ms run out is a timeout: the adapter's sweep by name settles it, where a delete by id would read not
179
+ * found and leave it. The first wait takes ms whole, each one after it what is left. A cancel is read before each wait
180
+ * (pause ends early on one, it doesn't throw), so none starts after it: an aborted build's wait would otherwise run on
181
+ * while its machine is deleted.
182
+ */
183
+ async #ready(id, ms, signal) {
184
+ const end = Date.now() + ms;
185
+ let timeout = ms;
186
+ for (;;) {
187
+ if (signal?.aborted)
188
+ throw new HostError("aborted", `the wait for the machine ${id} was aborted`);
189
+ try {
190
+ await this.machines.waitUntilReady(id, { timeout });
191
+ return;
192
+ }
193
+ catch (error) {
194
+ if (codeOf(error) !== "not_found")
195
+ throw error;
196
+ if (Date.now() + NOT_YET_MS >= end) {
197
+ throw new HostError("timeout", `boxd made the machine ${id}, then read it not found until the wait for it ended (${error instanceof Error ? error.message : String(error)})`);
198
+ }
199
+ await pause(NOT_YET_MS, signal);
200
+ timeout = Math.max(1, end - Date.now());
201
+ }
202
+ }
203
+ }
169
204
  /** The machine a failed create made, deleted by its id; the step's own error comes back, the delete's outcome in its message. */
170
205
  async #unmade(id, error) {
171
206
  let outcome;
@@ -270,7 +305,7 @@ class BoxdHost {
270
305
  });
271
306
  ids.add(made.id);
272
307
  const ms = Math.max(1, end - Date.now());
273
- orThrow(await race(this, this.machines.waitUntilReady(made.id, { timeout: ms }), `the build machine ${made.id}'s start`, ms + CALL_SLACK_MS, signal));
308
+ orThrow(await race(this, this.#ready(made.id, ms, signal), `the build machine ${made.id}'s start`, ms + CALL_SLACK_MS, signal));
274
309
  const what = `the desktop recipe (mousepad) on the build machine ${made.id}`;
275
310
  await runChecked(this, made.id, ["sudo", "-n", "sh", "-c", DESKTOP_RECIPE], { ms: Math.max(1, end - Date.now()), signal, what });
276
311
  await this.snapshots.create(made.id, name);
Binary file
Binary file
@@ -1,4 +1,4 @@
1
1
  {
2
- "version": "0.1.0-beta.67",
2
+ "version": "0.1.0-beta.69",
3
3
  "source": "sha256:ca76a29aaa9ab0216cefc6badb124b6ab39a5a0094b984fa8d26537633ccad1e"
4
4
  }