AGENT.RUN() / GET STARTED

Set up AgentRun
with your agent.

Follow the AgentRun quickstart with your coding agent. Open the prompt in an app, or copy it into your terminal agent.

Download Markdown

DOCUMENTATION / HARNESSES & COMPUTERS

Based on AgentRun release · Synced .

@parcha/agentrun-computer

Published from the next release; nothing else in the repository uses it yet.

npm install @parcha/agentrun-computer@latest
import { providerFor, providerModule } from "@parcha/agentrun-computer";
// One provider's class, from its own subpath: the package root loads no provider.
import { DockerProvider } from "@parcha/agentrun-computer/docker";
// The mount rule alone: loads no provider, no vendor SDK and no conformance code.
import { checkMount, readBackOf, WORKSPACE, type MountSpec } from "@parcha/agentrun-computer/mount";

The package root holds the protocol, the registry and the descriptors, and loads no provider: a provider loads by its id (providerFor(id, options), which imports that one provider's file), or from its subpath (/docker, /daytona, /modal, /e2b, /orgo, /orgo-desktop, /phone-harness, /browserbase, /kernel, /local-chrome, /boxd, /smolcloud). A provider's option types (DockerProviderOptions, ModalProviderOptions and the like) come from its subpath too, not the root.

The package carries the daemon for Linux amd64 and arm64 in dist/, so a provider runs it with no Go on the host. A vendor's SDK is the host's: Modal's modal package is imported only when the Modal provider is built, and the package depends on nothing. A provider's mount kinds are its descriptor's mounts, read with descriptorOf(id).mounts, which loads no provider file at all.

Every install carries all of dist/, whatever the host's architecture and whichever provider it uses: both daemons (a Docker host on either architecture and every remote provider use one of them, and the archive does not know which), every provider's module, and the conformance CLI and suite with the live sweep. At 0.1.0-beta.31 (npm pack --dry-run --json) that is 122 files, 3,688,167 bytes packed and 9,234,731 unpacked; the two daemons are 8,216,900 of the unpacked bytes (4,219,042 amd64, 3,997,858 arm64) and the conformance code 238,421. The trade: no Go, no download and no install script on the host, for one daemon more than the host runs: about 4 MB unpacked and 1.6 MB compressed.

The open platform's computer protocol. A computer is anything an agent can run commands on: a container, a microVM, a full VM, a machine. The protocol has two layers:

  • A daemon in every computer. computerd is one small static Go program (Linux, amd64 and arm64, no cgo). It speaks JSON-RPC 2.0, one JSON object per line, over stdin and stdout, so it works in a computer with no network.
  • One provisioner per vendor. A provisioner makes, finds and ends computers, and opens a stream to the daemon inside. It never runs commands itself: the daemon does. This package has five: Docker, Modal's VM runtime, Daytona, E2B (desktops) and boxd (microVMs, contributed by Michiel Voortman), each one line of the provider registry (see Adding a computer).

The protocol is published as a spec, spec/computer/, at protocol version 0.2 (PROTOCOL_VERSION, which hello carries as protocol). Its JSON Schema and constants are generated from src/protocol.ts by node scripts/generate-computer-spec.mjs, and a test fails when they drift.

What it does today

The daemon answers hello, ping, exec.run, the files.* methods, tar.*, the process.* methods and deadline.extend; hello reports kind linux and groups ["exec", "files", "processes"] (see The protocol extension). With an X display it also answers screen.shot, screen.read, input.actions and the apps.* methods, and reports kind desktop with screen, input.pointer, input.keys and apps (see The X11 shim).

Kinds: the computer an agent is given

Two axes. The machine kind is the protocol's, capabilities().kind (linux, desktop, android, ios, browser; below). The setting kind is what an agent is given in Settings, computer: { kind, provider? }: one of five, each a set of machine kinds and capability groups (src/kinds.ts, SETTING_KINDS). The model's tools are not here: they live in the kernel's tool registry, keyed by these groups.

The protocol extension: kind, daemon modes, screen, input, apps, lifetime

The types and the conformance cases for computers past a Linux shell: desktops, Android and iOS phones. This package has the types, the cases, the daemon's screen and input on X11 (The X11 shim), the desktop fixture and a Docker desktop; a phone provider comes in a later change. Docker declares linux with computerd as PID 1 unless it is made a desktop, so on a plain Docker computer every new case skips in words.

Settings

The library takes options only. Every provider is built by its file's create(options) (or its class), and every setting, a vendor key included, is an option: no provider reads an environment variable for a setting, and no provider file names one. A key is never logged or echoed in an error. Whoever builds a provider owns the names its settings live under:

  • serve, at the cutover, reads its own existing names and passes them in, so an owner's settings keep working:

    serve's name becomes
    DAYTONA_API_KEY Daytona's apiKey
    DAYTONA_API_URL Daytona's apiUrl (unset: Daytona's own, https://app.daytona.io/api)
    DAYTONA_TARGET Daytona's target
    MODAL_TOKEN_ID, MODAL_TOKEN_SECRET Modal's tokenId, tokenSecret
    AGENTRUN_BOX_APP Modal's app (serve's default, agentrun, when unset)
    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
    E2B_API_KEY E2B's apiKey: serve's new name for the E2B box
    BROWSERBASE_API_KEY, BROWSERBASE_PROJECT_ID Browserbase's apiKey, projectId: the names pi-browser reads today
    KERNEL_API_KEY Kernel's apiKey: the name pi-browser reads today
    BOXD_API_KEY, BOXD_ORG, BOXD_REGION boxd's apiKey, org and region (unset: the key's own org, the API's home region)
    SMOLCLOUD_API_KEY smol cloud's apiKey
  • the conformance CLI and the live harness (src/conformance/: the CLI, each provider's conformance module and the sweeps) read their own COMPUTER_<ID>_* names, the ones the live scripts set, through each module's settingsFromEnv(env), and pass them in. Each provider's section lists its names. They never read serve's names or a vendor's bare variable, which on a shared host may hold another account's key.

A default never comes from the environment either: Docker's daemonCache defaults to ~/.cache/agentrun-computer whatever XDG_CACHE_HOME says, and a caller that keeps its cache elsewhere passes daemonCache.

Two lines of the library touch the environment, each a guard against a vendor SDK that reads it on its own, not a setting:

  • Modal, MODAL_SERVER_URL (modalClient in src/modal.ts). The SDK takes its server from MODAL_SERVER_URL and has no option for it, so the provider refuses to start while it is set, and sets it to options.serverUrl only while it constructs the client, putting back what was there after. process.env is the whole process's, so constructions run one at a time: none sees another's server.
  • E2B, E2B_SANDBOX_URL (ambientProblem in src/e2b.ts). The SDK sends every sandbox call to it when it is set, and no option clears it, so the provider refuses to start while it is set. It only reads.

A proxy isn't read from the environment either. E2B's SDK and Morph's SSH gateway, the two clients Node's own proxy doesn't reach, follow the one the process installed into Node (--use-env-proxy, NODE_USE_ENV_PROXY or http.setGlobalProxyFromEnv, which serve calls at start), as fetch does: src/env-proxy.ts reads it from Node's https.globalAgent. A process that installed none has them go direct.

scripts/check-env.mjs holds the library to this: it reads every file under src/ outside src/conformance/, those in its directories (src/docker/) included, with TypeScript's parser and fails on any use of process.env (dotted, bracketed, destructured, aliased, through globalThis or an import of node:process) but these two, each by its variable, its file and its function. test/providers.test.mjs runs it, checks the files it read, and runs it on fixtures of every evasion it catches.

Docker

Daytona

E2B

Agent37

Morph

Orgo: Windows and macOS desktops (parked)

Orgo offers its Linux desktop alone, which runs computerd (src/orgo.ts). Its Windows and macOS desktops are parked: the descriptor lists them in parked (ORGO_PARKED), so PROVIDERS offers no configuration of either, Settings → Computers lists no Windows or macOS image, and an agent whose computer names windows or macos is refused at its run's start in words naming the image Orgo offers, linux. They do not run computerd either: computerd for Windows and macOS is CP-8, deferred. create({ os: "windows" | "macos", apiKey, workspaceId }) still builds an OrgoDesktopProvider (src/orgo-desktop.ts) with daemon none, for the conformance suite and the tests. It answers the protocol's methods in process over Orgo's REST API, as the phone harness and Browserbase do. Its spec's image is "windows" (ORGO_WINDOWS_IMAGE, Orgo's Windows Server 2019) or "macos" (ORGO_MACOS_IMAGE): the one the provider was built for.

Browsers: Browserbase and Kernel

A browser is a computer of kind browser: a vendor's browser session that answers CDP. No computerd runs (daemon none): the provider answers hello and ping itself, from the vendor's API, and refuses any other method in words, since a browser is driven over CDP. connect(ref) reads the browser first (one that has ended, or that the vendor no longer knows though its URL is held, is gone), then gives a connection whose cdp.url is the vendor's signed CDP URL, which a driver dials; stream(ref) gives the vendor's live view. Both URLs are secrets: they are held in memory (a UrlStore) and are never in a ref, a list, an error's words or a report. client stays a ComputerClient, so every caller of connect reads a browser's connection as it reads any other.

A local browser: this machine's Chrome, no keys

The local-chrome provider (Local Chrome, local-chrome.ts) is a computer of kind browser that is the Chrome or Chromium on the machine AgentRun runs on. No vendor, no key, nothing billed.

Phone harness (the phone kind)

boxd

smol cloud

Conformance

A provider for another vendor passes the same suite as Docker's, with one command. The suite is data: each case in src/conformance/cases/ names its level, its group (health, exec, files, process, provider, drift, isolation, mount, screen, input, touch, apps, lifetime, browser, gpu) and the capabilities it needs, and uses only ComputerProvider, ComputerClient and the suite's assertion helpers, so the same cases run against a provider with daemon none.

Persistent computers: an agent's own

A run's computer belongs to its run: it has a deadline (lifetimeMs, required), and the janitor or the vendor ends it once the deadline passes. A persistent computer belongs to an agent instead. It outlives the agent's runs, which take it one at a time, and it keeps its files between them. The contract, in src/provider.ts and src/labels.ts:

  • Declared. A provider that keeps computers for agents declares capabilities().persistence: { keepsState: true, resume }. keepsState: a detached computer keeps its files. resume: true when it comes back as it was, its processes still running; false when it boots again from its kept disk. A provider that declares none refuses spec.owner in check(), in words, before any vendor call, and refuses release(ref, "detach"), the computer left as it was.
  • Owned. spec.owner: { agent, idleTtlMs? } makes the computer the agent's. It has no run deadline: the rule that refuses a computer with no deadline is a run's computers' alone, and an owned spec that names lifetimeMs is refused (checkTenure(spec, capabilities) holds both rules, for every provider's check()). The computer carries the owner label, agentrun.owner=agent:<id> (OWNER_LABEL), and agentrun.idle-ttl-ms (IDLE_TTL_LABEL) when the owner set an idle TTL; ownerLabels(owner) gives both and ownerOf(labels) reads them back.
  • Detach. release(ref, "detach") stops the computer with its state kept. It stays the agent's, listed stopped, with detachedAt, when it was detached. Only an owned computer detaches: a run's computer refuses it in words and runs on. "delete" deletes an owned computer, and only the agent or its owner asks for that: the caller's rule, not the provider's.
  • Attached under a new claim. A run takes the computer with attach({ id }, { claim: { run, epoch } }). The provider brings it back (starts it, when detached) and records the claim, so the computer carries the run's agentrun.run and agentrun.epoch and releaseOlder of that run finds it. A claim of the same run below the epoch the computer carries is refused as fenced, with nothing changed. A claim on a computer with no owner is refused: a run's computer belongs to its run.
  • The janitor. A computer is owned when it carries the owner label or its provider's list() marks it owned: true (with owner when the listing knows it: a vendor whose stopped computer shows no labels). sweep never deletes an owned computer by a deadline. It deletes one only when its owner agent is gone (ownerGone(agent), the caller's answer, in SweepOptions), or when it has been detached for longer than its owner's idle TTL. An owner label it cannot read keeps the computer: the janitor never deletes an agent's state on a rule it cannot read. On a provider that declares persistence it sweeps owned computers under lifetime "vendor" too, since no vendor ends them. releaseOlder detaches an owned computer of a lower epoch and never deletes it: the new claim attaches it.
  • Conformance. provider.owner and provider.detach are Core for every provider: check() refuses an owner without persistence, and a lifetime with one; a run's computer refuses detach and runs on. provider.persistence is Full, run where persistence is declared: create with an owner, write a file, detach, attach by id under a new claim, read the file back (with resume, find the process still running), refuse a fenced claim, then delete.

test/fake-computer.mjs's persistence option is a provider that declares it and passes the cases. Orgo's provider is the first vendor to wire it.

Adding a computer

A new computer is one provider file and one descriptor, src/descriptors/<id>.ts, declared once and listed in DESCRIPTORS (src/descriptors/index.ts). Everything else is derived from the descriptors: the registry (src/providers.ts, id to load()), the kind registry's PROVIDERS (Settings' rows), and the ids. The conformance CLI (and serve) resolve providers through them, so neither needs an edit:

export const FLY = defineProvider({
	id: "fly",
	label: "Fly",
	keys: [{ name: "FLY_API_TOKEN", option: "apiToken", required: true }], // each key and the create() option it fills
	metered: true,
	mounts: [],
	network: ["none", "open"], // the network forms its computers make: none, open, allow
	capabilities: [{ kind: "linux", groups: ["exec", "files", "processes"] }], // one per configuration
	load: () => import("../fly.js"),
});

A descriptor is data and a lazy load(): it imports ../descriptor.js and other descriptors alone, so loading the registry, the kind registry or the package root loads no provider and no vendor SDK. defineProvider checks it when it is declared (descriptorProblems), in words. Its fields: id, label, keys (each key's name, the option it fills, and whether it is required), settings (a setting that is no key but fills an option, with its default), metered, mounts, network (the network forms its computers make, at least one of none, open and allow), capabilities (the kind and groups of each configuration), defaultImage (by setting kind), prepareImage (a provider whose prepareImage() answers its image before a run: it builds, pulls or names it), imageEnv (the server's environment variable that, when set, names the image of every computer of the provider, as Daytona's AGENTRUN_DAYTONA_SNAPSHOT), connect (whether its machines dial the server: dial always, as Fly Machines' and Cloudflare's; either, as its connect option says, which one of its settings fills, as E2B's, Daytona's and Modal's; absent, never), local (a computer on this host), and ledger (the option a provider's ledger fills). connectOf(descriptor, options) answers dial or exec for a provider made with those options, without building it; its built host's facts.connect is the same answer, and a server reads it to say where its runs can't take a dial (a runner in a process of its own). providerFor(id, options) builds a provider by id from its options and refuses an id it does not hold, naming the ones it does. The provider file, src/<vendor>.ts, exports what a ProviderModule is:

  • the provider class, which implements ComputerProvider and reports the registry id as its id;
  • create(options), the provider built from its options alone, its key included, and refused in words when one is missing or wrong, never echoing a key. It reads no environment (see Settings), and exports no names of variables;
  • optionally conformance, () => import("./conformance/<vendor>.js"): a module that reads the run's settings from the environment by its own COMPUTER_<ID>_* names (settingsFromEnv(env), with ENV listing every name it reads; never a vendor's bare variable such as DAYTONA_API_KEY, which on a shared host may hold another account's key, not even as a fallback), bounds a conformance run's computers and makes the drifted provider (createProvider(), createDriftedProvider(), conformanceImage(), conformanceNotes), building them through create(). Without it the CLI runs create()'s provider with the CLI's options, and the drift case skips, so Core does not pass.

Docker's conformance module reads COMPUTER_DOCKER_DAEMON (daemonPath; unset, create() takes this package's daemon for Docker's architecture, from docker version), COMPUTER_DOCKER_DAEMON_CACHE (daemonCache) and COMPUTER_DOCKER_USER (user); the provider's image is an option only, which no module reads from the environment (see "The image"). Modal's, Daytona's and E2B's read the names in their sections. test/providers.test.mjs holds every provider file to its registry line and its line to this shape, checks that the CLI's usage names every id, and runs scripts/check-env.mjs on src/. Run the suite on the new computer, by path before its line exists and by id after:

npm run conformance -w @parcha/agentrun-computer -- --provider ./packages/computer/dist/fly.js
npm run conformance -w @parcha/agentrun-computer -- --provider fly

Build

npm run build -w @parcha/agentrun-computer          # the TypeScript, into dist/
npm run build:daemon -w @parcha/agentrun-computer   # dist/computerd-linux-amd64 and -arm64, and dist/computerd.json

build:daemon builds the daemon with Go 1.24 or newer when Go is on PATH, and records the daemon source it came from in dist/computerd.json. Without Go, it takes both binaries from this version's package on npm, but only when that package's computerd.json names the same daemon source as the checkout (scripts/daemon-source.mjs); otherwise it stops and says to install Go. Each release carries the record, so a checkout of a released version needs no Go until its daemon changes.

Tests

npm test -w @parcha/agentrun-computer               # unit tests: no Go, no Docker
cd packages/computer/daemon && go vet ./... && go test ./...
AGENTRUN_COMPUTER_LIVE_DOCKER=1 npm run test:docker -w @parcha/agentrun-computer
AGENTRUN_COMPUTER_LIVE_DAYTONA=1 COMPUTER_DAYTONA_API_KEY=... [COMPUTER_DAYTONA_SNAPSHOT=<snapshot>] npm run test:daytona -w @parcha/agentrun-computer
AGENTRUN_COMPUTER_LIVE_MODAL=1 npm run test:modal -w @parcha/agentrun-computer   # also needs COMPUTER_MODAL_TOKEN_ID/SECRET, for an account you can bill
AGENTRUN_COMPUTER_LIVE_E2B=1 npm run test:e2b -w @parcha/agentrun-computer       # also needs COMPUTER_E2B_API_KEY, for an account you can bill, and the e2b package
AGENTRUN_COMPUTER_LIVE_BOXD=1 npm run test:boxd -w @parcha/agentrun-computer     # also needs COMPUTER_BOXD_API_KEY, for an account you can bill, and the @boxd-sh/sdk package

npm test also runs test/local-chrome-live.test.mjs on a real Chrome where one is on PATH (or CHROME_PATH names one) and starts here with its sandbox on: it creates a local browser, drives it over CDP, checks that a service on this machine's loopback is out of its reach, and releases it. Elsewhere it skips with the reason.

Where Xvfb is on PATH, the Go tests also run the X client, and screen and input against the fixture, on a real X server; elsewhere those tests skip in words and the fake X server's tests still run.

The live tests run the conformance suite on Docker, one test per case, on a plain computer and on a desktop built from test/fixtures/desktop/Dockerfile by ensureImage with computerd-fixture built from daemon/cmd/fixture, and the CLI against alpine:3.20; the rest of them check what only Docker shows (the user, sizes, tmpfs mounts and hardening flags in docker inspect, the daemon mount, the socket directory, hello's arch against Docker's, /work as the user's home, the daemon's exit 0 on docker stop and at its deadline, attach by a container's name). They need Docker, debian:bookworm-slim and alpine:3.20 pulled, both builds, and Go on PATH (the drift case builds a daemon of another version). They use the daemon for Docker's own architecture, and remove every container they make by its exact name, pass or fail. test/docker/image.docker.test.mjs builds fresh alpine:3.20 recipes: once for three concurrent callers, reused on the next call, from three processes at once, and a broken one refused in words; it removes each tag it made. Another, test/docker/pid1-commands.docker.test.mjs, runs the adapter's pid1 entrypoint and install (Modal's) exactly as sent, in a Debian and an Alpine root container with no network, and checks that init comes up as uid 1000 with no capabilities and no_new_privs, and answers hello over computerd stdio. Those root containers keep Docker's default capabilities and add CAP_SYS_ADMIN and CAP_NET_ADMIN (init --own-network needs both, and Modal's root holds every capability), or every one (--cap-add ALL), with no --cap-drop: with --user 1000:1000, exec.run reads every thread of init and its own status with all five sets zero and NoNewPrivs 1; --user 0:0 has init refuse to start, and so does a root container without CAP_SETPCAP, in words. test/docker/loopback-block.docker.test.mjs starts init as Daytona, E2B and Modal start it, in an Alpine root container beside a stand-in agent (BusyBox nc as root on 2280 and 49983, on every interface): root reaches the stand-in, and a program of the computer's user, through exec.run, finds every port refused on both loopbacks and the container's own address, and 1.1.1.1:443 and example.com:443 refused though the container itself has Docker's bridge, sees lo alone, and still reaches a listener of its own; a root without CAP_SYS_ADMIN, and a container where another process holds the computer's uid, have init refuse to start in words. The Daytona and E2B command tests give their containers the same two capabilities. test/docker/e2b-commands.docker.test.mjs runs the E2B provider's install, init and bridge as sent, in a root container of the desktop fixture's image, starts Xvfb through the daemon on the display init was given and waits for hello to declare the screen, and checks that deadline.extend moves up to --max-deadline and no further. The programs the daemon starts get no DISPLAY of init's (it passes on only PATH, HOME, USER and LOGNAME): a caller that starts a GUI program gives it DISPLAY in the request's env, on E2B as on Docker. The surface is that caller for an agent: on a desktop whose hello names a display, shell.run and processes.start add it under the call's own env. processes.start is process.start with orphans: "keep", so an app (or the app a launcher forks) stays open after the call, where exec.run's guard ends everything its command started.

Acknowledgements

The daemon copies code, with credit, from two Apache-2.0 projects. NOTICE names them; UPSTREAM.json records each copied file, the commit, and what changed. It has no Go dependency outside the standard library: the terminal is opened with its own ioctls (pty(7)) rather than with github.com/creack/pty.

  • E2B infra, envd: the user, credential and environment setup of a process; a file's entry info and the listing to a depth.
  • Kubernetes agent-sandbox, sandboxd: the exit status and the bounded output of a run with limits; filesystem errors, mkdir, move and remove, and tar extraction confined to its directory; the process registry, and a process's stdin, signal and terminal resize.
  • E2B envd also gives the signal names, the process list and the terminal's read loop.
  • Rivet sandbox-agent's process runtime (Rust; no code copied) is the design reference for a bounded log per process, the process snapshot in a list, and reads that wait for output.