@parcha/agentrun-computer
v0.1.0-beta.353
Published
The open platform's computer protocol: a daemon in every computer, and one provisioner per vendor, starting with Docker.
Readme
@parcha/agentrun-computer
Published from the next release; nothing else in the repository uses it yet.
npm install @parcha/agentrun-computer@latestimport { 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, /groundbox, /vercel, /sprites, /instabox, /northflank, /maritime, /freestyle, /archil). 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.
computerdis 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).
→ {"jsonrpc":"2.0","id":1,"method":"hello","params":{"client":"me"}}
← {"jsonrpc":"2.0","id":1,"result":{"protocol":"0.2","version":"0.1.0-beta.30","os":"linux","kind":"linux","arch":"arm64","groups":["exec","files","processes"]}}
→ {"jsonrpc":"2.0","id":2,"method":"exec.run","params":{"argv":["uname","-m"],"timeoutMs":5000}}
← {"jsonrpc":"2.0","id":2,"result":{"exitCode":0,"stdout":"YWFyY2g2NAo=","stderr":"","timedOut":false,"truncated":false}}exec.runtakes argv, never a shell string. A shell is the caller's choice:["sh", "-c", "..."].- Each run has a guard: the daemon starts itself again as
computerd guard, a child subreaper for that one run, and the guard starts the program in a process group of its own. Whatever the program starts stays under the guard, even a child that callssetsidor double-forks, since the kernel hands an orphan to its nearest subreaper. When the program ends, the guard kills and reaps every process left under it, then reports the program's exit code or signal. A signal is named withoutSIG, here and inprocess.waitandprocess.list:"TERM","KILL"(a signal with no name is its number,"63"). On timeout, or when the call is cancelled with$/cancelRequest {id}, the guard sends SIGTERM to the group and every process under it, then SIGKILL 2 s later. A timeout is a result withtimedOut: true; a cancel is anabortederror. Nothing a run starts outlives it.timeoutMscounts from the call, the start included: a guard that never reports the program's start (its exec stalled on a filesystem) is killed with everything under it, and the run times out. stdoutandstderrcome back apart, in base64. Each keeps at most 360 KiB (maxOutput, the default and the most): both, in base64, fit one 1 MiB line. The rest is read and dropped, andtruncatedis true.- The environment is PATH (the daemon's), HOME, USER and LOGNAME for the user, then, when init relays to an egress
proxy (
init --egress, below),HTTP_PROXY,HTTPS_PROXY, their lowercase forms andNO_PROXY, thenenvover them. Nothing else of the daemon's environment is passed on. useris a name oruid[:gid]. A daemon without CAP_SETUID and CAP_SETGID cannot switch users and answersdenied. Init leaves itself no capability (below), so a command runs as the daemon's own user.- Requests run at once; replies may come in any order. A line over 1 MiB gets an error reply and the connection goes
on. When the input ends, what still runs on that connection is cancelled: an
exec.run, never a process. - Errors are
{code, message, data: {kind}}, with kindnot_found,invalid,timeout,aborted,denied,limit,unsupported,exists,not_diroris_dir.
Init, the socket and the bridge
computerd init --deadline <time> [--max-deadline <time>]is the computer's first process. It listens on a unix socket,/run/agentrun/computerd.sock(orAGENTRUN_COMPUTERD_SOCKET); the socket is 0600, so only the daemon's user can connect. Init does not make the socket's directory, since a non-root init cannot write under/run: the provider gives it, the daemon's user's alone (mode 0700). Init exits 1, saying why, when the directory is missing, is not the user's alone, or is not writable by it. Every connection is served by the same daemon with one process table, which is how a process outlives the call and the connection that started it. A socket left by an init that is gone is replaced; a live one is refused.computerd init --deadline <time> --user <uid:gid>is for a vendor that runs every computer as root and has no user of its own to give (Modal), or whose images' privilege tools cannot be relied on (Daytona). Init starts as root, makes$HOMEand the socket's directory that user's alone (0700, never through a symbolic link), and becomes uid:gid with no supplementary groups, dropping its privileges on the way as below: from there it is the daemon a Docker computer runs. WithDISPLAYset (a desktop), init first gives a uid and gid with no entry in/etc/passwdand/etc/groupone, namedagentrun-tool(oragentrun-<id>when that name is taken), home$HOME, shell/bin/sh: a desktop's programs look their user up (D-Bus's session bus, a terminal's shell).--user 0:0is root with no capability. Without root, init refuses--userin words; a Docker computer is given its user bydocker run --userand never passes it.computerd init ... --user <uid:gid> --own-networkis how every remote provider starts init (Daytona, E2B, Modal). A remote vendor runs its own agent in the computer beside the daemon's programs (Daytona's toolbox on 2280, E2B's envd on 49983), listening on the loopback and on every address the computer has and running commands as root, or as a user with sudo, for whoever reaches it: without this, any program could ask it for root. Init, still root: refuses uid 0 for its programs (root shares its uid with every root process of the vendor's); refuses to start while any other process holds that uid (one could be signalled, traced or written to by them, and a vendor's agent among them would be theirs to command), naming each; moves every one of its threads into a new network namespace and brings its loopback up over rtnetlink (RTM_NEWLINK with IFF_UP on lo's index, asip link set lo updoes; and RTM_NEWADDR for 127.0.0.1/8 where the kernel gave lo none), never by the SIOCSIFFLAGS ioctl, which gVisor's netstack refuses in a new namespace (ENOTTY, live on Modal's gVisor, 11-11). It reads back lo up and running, 127.0.0.1 on it and a listener there reached, and that no thread stayed behind and that the loopback alone is up or addressed (a kernel with the tunnel modules loaded gives every new namespace its fallback tunnels, tunl0, gre0, sit0 and the rest, down with no address: they stay so, since no program holds CAP_NET_ADMIN, and computerd's probe reports any it could bring up, which every read-back refuses); then drops as below, and installs a seccomp filter on every thread that refuses (EPERM) a socket of familyAF_VSOCK(a network namespace does not cut vsock, where a virtual machine's agent may listen) andio_uring_setup(its rings open sockets past a filter onsocket(2)), and givesENOSYSto every call of another architecture or table (32-bit x86, x32). So init and every program it starts reach their own loopback and nothing else: no address of the computer's, no listener on its loopback, no abstract unix socket outside, no vsock. The vendor's exec ofcomputerd stdiostays outside and still reaches init's socket: a unix socket with a path is not in a network namespace. It needs root with CAP_SYS_ADMIN and CAP_NET_ADMIN (a VM's root, a privileged container); without them, or with any read-back short, init refuses to start in words and the computer fails closed.--own-networktakes no--egress; for a spec whose network isopenor a list it takes--network open|allow:<list>, and init, still root and in the machine's own network, first starts the egress proxy (daemon/internal/egress): as nobody, on a Unix socket root's and the tool user's group's alone (/opt/agentrun/egress/egress.sock), to the public internet only (Docker's egress table, plus the machine's own addresses), and with a list to its hosts alone, refused before any lookup. Init relays its loopback port 3128 to that socket and gives its programs the proxy env; their namespace stays their loopback alone. With--networkit also takes--public-egress <IPv4>:<port>(the adapter'spublicEgress): the proxy then opens each tunnel to port 443 (HTTP CONNECT or SOCKS5 CONNECT) that passed every check to that address instead of the checked one, carrying the program's bytes unchanged, so a gate there admits by the TLS ClientHello's server name. The proxy reads that ClientHello first and carries the tunnel only when its server name is the host the checks passed (so a listed host's tunnel never carries an off-list name to the gate); a tunnel to an IP literal, or whose first bytes name no host or another, is closed with nothing sent. Plain HTTP and every other port dial the checked address. Unset, nothing changes; a malformed value, or one without--network, and init refuses to start. The code isdaemon/internal/isolate;test/docker/loopback-block.docker.test.mjsruns each provider's start in a root container beside a stand-in agent on 2280 and 49983.- Where root may not make the network namespace, init makes it inside a user namespace. Root holds no
CAP_SYS_ADMIN on gVisor (Modal's GPU runtime), so
unshare(CLONE_NEWNET)is EPERM. It may make a user namespace with a network namespace inside it (a live probe on Modal's gVisor, 11-11). Init doesn't ask the vendor which it is: it tries the plain namespace first, and on EPERM alone (isolate.ErrNoNetworkNamespace) it takes this way, whatever the vendor.- Init starts itself again as
computerd userns-init --started-in <its network namespace>: a child in a new user namespace that maps every uid and gid to itself, and a new network namespace. The root parent writes the map, which needs CAP_SETUID and CAP_SETGID. The map keeps every id as it is, so the files the programs make, HOME, and the run's folder belong to the same uid inside and out. - The child does all of the above but make the namespace. Before touching anything, it reads back
(
isolate.KeepOwnNetwork) that no thread is in the namespace it was started from. Then it brings the loopback up over rtnetlink and reads it back, as above. The live T4 run at the fallback's first head (11-11) made the user and network namespace, then failed at lo on the ioctl. - The first init keeps no capability (no_new_privs, every set empty). It passes SIGTERM and SIGINT on, reaps, and exits with the child's code.
- If neither way works, init refuses to start in words that name both, and the computer fails closed.
- hello says which fence holds,
fence: "netns"or"userns-netns". Every provider that starts init with--own-network(Daytona, E2B, Orgo, Modal) refuses a hello that names neither.
- Init starts itself again as
- Init drops its privileges itself, as any user, root included, before it listens, so the line holds on every
vendor and not only where the provider drops capabilities (Docker:
--cap-drop ALL). On every thread it setsno_new_privs; drops from the bounding set each capability up to the kernel's last (/proc/sys/kernel/cap_last_cap) that is still there; makes the uid change, with--user; empties the ambient set and, bycapset, the effective, permitted and inheritable sets (a uid of 0 keeps them through any uid change); and reads all of it back. So init, every program it starts and every program those start hold no capability in any set (CapInh,CapPrm,CapEff,CapBndandCapAmball0000000000000000,NoNewPrivs1), and with the bounding set empty not even a program root starts gains one. Root without a capability is root to the file system's permission bits only: it owns what uid 0 owns. Emptying the bounding set needs CAP_SETPCAP; a capability already gone is not dropped again, so a process started with an empty bounding set needs none. When a capability cannot be dropped (EPERM, such as a user with a bounding set and no CAP_SETPCAP, asgo testruns on a host), or the binary links cgo (one call cannot reach every thread), init refuses to start, in words, and exits 1. - That refusal is policy: init fails closed. A vendor that starts the daemon as a non-root user with a bounding
set it cannot empty (a Kubernetes
runAsUserwithoutcapabilities: drop: ["ALL"], say, ordocker run --userwithout--cap-drop ALL) gets no computer, not a computer that runs anyway. The line this package holds is that every set reads back zero, so no program in a computer holds a capability or can gain one.no_new_privsalready stops a gain throughexec(a setuid-root file, file capabilities); the empty bounding set is the second, independent limit on the same gain, and init cannot prove from inside that a bounding set it was handed is harmless on every kernel and vendor it runs on. So it does not run with capabilities it cannot prove gone. A refusal is said, in words naming the capability and EPERM, and is fixed where it starts: drop every capability for the user, or start init as root holding CAP_SETPCAP so it drops them itself. A start that went on would be silent, and every program in the computer would inherit it. - The daemon's Go tests run without cgo, as computerd is built. Go builds with cgo wherever it finds a C compiler,
so a plain
go test ./...makes test binaries that link cgo, and in one of those init refuses to start for cgo (ENOTSUP) alone. The test entry ofcmd/computerdandinternal/daemon(internal/nocgo, fromTestMain) builds such a package's test binary again withCGO_ENABLED=0 go test -cand the-tagsand-ldflagsthe first was built with (read from its build info), runs it with the same arguments and environment, and exits with its code; a binary without cgo runs its tests itself, and a-racebuild (which needs cgo) skips the tests of the drop. On a host as another user the refusal for EPERM and both deadline tests run (init takes its deadline and refuses for the bounding set). The root path (TestBecome...,TestUnprivilegedLeavesRoot...) needs root with capabilities and skips there; CI'scomputer-dockerjob covers it with the pid1 commands matrix (test/docker/pid1-commands.docker.test.mjs: root containers with Docker's default capabilities and the two--own-networkneeds, or--cap-add ALL, as 1000:1000, the refusal of 0:0 and the refusal without CAP_SETPCAP), and computerd's end at its deadline with the Docker live tests. The test binaries (CGO_ENABLED=0 go test -c) also run as root in a container by hand:internal/isolate's and the isolatedTestBecome...need CAP_SYS_ADMIN and CAP_NET_ADMIN (docker run --cap-add SYS_ADMIN --cap-add NET_ADMIN), and the refusal without them needs a container with Docker's defaults. computerd probe [--sockets] [--connect <host:port>[/udp]]...prints one JSON line: the uid and gid it runs as, the kernel's release,interfaces(the network interfaces its network namespace holds:["lo"]alone under--own-network),reached(the targets that answered),accepted(the targets that accepted a TCP connection and sent nothing back) andresults, each target'sprotocol,outcome(refused,acceptedoranswered),bytesanddetailin words. It always adds what network none is proven by from inside:routes, every IPv4 and IPv6 route the namespace holds, read over rtnetlink (RTM_GETROUTE), eachfamily(inetorinet6),dst(CIDR;0.0.0.0/0or::/0is a default route),type(unicast,local,unreachable, ...),tableandiface(""with no output interface), ornullwithroutesErrorin words when the dump could not be read whole (one that ends withoutNLMSG_DONEis not whole);nameservers,/etc/resolv.conf's nameserver addresses (the resolver library's127.0.0.1and::1when it names none); anddns, the TCP and UDP sockets that listen on port 53 in the namespace (listeners, as below) and what of them it could not read (incomplete). With--socketsit adds the isolation case's two listings:sockets, the unix sockets it can connect to, by path or by abstract name (@..., which its network namespace holds), andlisteners, the TCP and UDP sockets that listen in its own network namespace (TCP in LISTEN and UDP bound with no peer, read from/proc/net/tcp,tcp6,udpandudp6), each with itsprotocol,address,port,uid, theownerthat holds it (pid N (command), where/procshows that process's descriptors) andcomputerd(that owner runs computerd's own program); each listing names inincompletewhat it could not search or read.isolation.vendor-agentfails on a listener that is not computerd's; under--own-networkcomputerd listens on nothing there, so on any listener. A provider whose vendor reads nothing back runs it throughexec.run(below, Modal), under the rule in Network none, read from inside.computerd probe --diagnoseasks more: for 1.1.1.1, 8.8.8.8, 9.9.9.9 and 151.101.1.57 (Fastly's anycast edge, which is no resolver) on 443/tcp, 80/tcp and 53/udp it reportsrefused(no TCP accept, no UDP answer),accepted(an accept, no answer) oranswered(a TLS ServerHello, anHTTP/1.xstatus line, a DNS response with the query's id), with 3 s to connect and 3 s to answer, 15 s in all and at most 4 KiB read per check, and averdict:egress,accepted-onlyornone. It sends nothing of the computer's: a ClientHello with a random nonce,HEAD / HTTP/1.0, a query forexample.com.computerd stdiois a thin bridge: it connects to the socket (waiting up to 3 s for a computer that has just started) and copies bytes both ways until either side ends. With no daemon to reach it says so on stderr and exits 1; it never serves on its own.computerd pair <server URL> [--name <name>],computerd attachandcomputerd unpairmake a Linux box of your own a paired computer: pair reads the console's code from stdin and keeps the token in a file only its user can read, attach dials with it, unpair deletes it (attach.md, A Linux box). A box with a display pairs as a desktop; one with none (alinuxhello) pairs as a sandbox that holds a run's folder as a synced folder in its/workspace, a directory of init's user's own, mode 0700, never a link, made once as root with a tmpfiles.d line. A run's shell can read and write everything that user can, so make it a user of its own (useradd --system --create-home agentrun, no lingering, no crontab), never a person's login user.- Init is a child subreaper (PID 1 in Docker is one anyway) and reaps every orphan. It also sweeps, on each SIGCHLD and
once a second: a child of its own that is not one of its guards can only be an orphan whose guard died (a program can
kill its own guard, since both run as the same user), so it is killed with everything under it. A process orphaned by
something run with
docker exec, outside the daemon, is ended the same way. - On SIGTERM or SIGINT (
docker stop), and at its deadline, init first stops taking new programs: from then onprocess.startandexec.runare refused asunsupported("the computer is shutting down"). It waits (up to 3 s) for the starts already under way to start their program, then sends SIGTERM to every guard, each of which ends its program's group and descendants with SIGKILL 2 s later; whatever is still under init 5 s after the SIGTERM is killed, and init exits 0. So every program that started gets SIGTERM before any SIGKILL. Connections stay open until init exits, so reads, waits and lists still answer. One shutdown serves all three. - A guard also ends its program when its control pipe from the daemon closes, so no program outlives the daemon.
deadline.extend({ at })moves init's deadline toat(an ISO time) and answers{ at }, the deadline it holds after. It refuses in words an earlier time (invalid), one past--max-deadline, the most the provider allowed at start (limit), and any move when init got no--max-deadline(unsupported); a refusal moves nothing. Init refuses to start with a maximum before its deadline.
Network none, read from inside: nothing answers
Where a vendor reads no network policy back, computerd probe stands for one, and network none holds only when
nothing answers within 10 s: a target counts as reached only when bytes come back from it. One rule for every
provider.
The gate, before the first call, on every network. A hosted provider (Modal, E2B and the others built on
HostedProvider) starting a computer proves from the sandbox's own state beforecreateanswers, in the targetless probe it already runs for its uid, gid and kernel (no exec of its own), that its programs have no way out of their namespace: no interface up butlo, no route out (no default route, IPv4 or IPv6, and none on another interface; anunreachable,blackholeorprohibitroute drops what it matches and is no way out), and no resolver the namespace can reach (nameserversread, and no port-53 listener in the namespace). The rule is the same under none, open and a list: under open or a list the programs' namespace is network none's, and they reach out only through init's relay on their own loopback (127.0.0.1:3128), which carries each connection over a Unix socket to the egress proxy outside, where names resolve; so no resolver is needed inside. Routes, nameservers or listeners it could not read prove nothing and refuse alike. On any refusal the computer is deleted andcreatefailsrefusedin words naming the network declared, such asnetwork: declared none, read back a route out: inet unicast 0.0.0.0/0 dev eth0,network: declared open, …or, for a list, by its count,network: declared allow (3 hosts), …; the run's first call never goes out. It costs one route dump (about 1 ms) and the port-53 listing's reads, which run beside the rest of the probe. Orgo's Linux desktop (network none alone) runs the same gate at create, and on an agent's computer whose daemon an attach installs again. Attach andnetwork(ref)read as before. A unix socket that reaches out of the sandbox is not a route and is not read here.Open and a list: the outside addresses before the answer. After the gate, a computer under open or a list tries the outside addresses and init's relay before
createanswers, as before: a direct answer from any outside address refuses it, the relay must answer, and the proxy's policy file must serve the form asked. The outside is reachable through the proxy there, so this is its tripwire, run before the answer; it gets noCreatedComputer.tripwire.The tripwire, beside the first call (network none). The outside-address probe (the targets below) no longer runs before
createanswers: it starts once the gate passed and runs beside the run's first calls, asCreatedComputer.tripwire. On Orgo it tries Orgo's agent's ports on both loopbacks beside the outside addresses. The probe runs on create's own connection, which the first connect shares; a probe that gets no answer there within its bound (probeMsand 5 s of slack: a big answer can hold the stream behind it) is tried once more on a bridge of its own before anything is read of it, so a tripwire that fails for no answer takes up to twice that bound (70 s at the defaults). A probe the daemon answers, whatever it says, is never tried again. The claim sends each call at once and holds its answer until the tripwire settles. On any reach, or a probe that could not be run or read (an error proves nothing, so it is never a pass), the provider deletes the computer and the tripwire failsrefusedin words; every held answer is that refusal, every later call is refused before it is sent (the provider's delete may have failed, so nothing more reaches the computer), the run ends failed in the same words, and the claim never makes the computer again in its place. The claim watches the tripwire from create's answer, before it connects: one that fails while the connect is out (the delete then answers the connect gone) still ends the run in its words, at the claim, at the run's first call or in place of a lost computer. The conformance run treats a computer as ready only once its tripwire settled ok: a failure fails the case that needed it in its words, and the computer is deleted after the tripwire settled. A case that judges whether create made a computer (a planted key's, a speccheck()refused) still sees that it did, whatever its tripwire read. A call cancelled while its answer is held answersabortedat once, but a computer is released only after its tripwire settled, so a run cancelled under it ends once the probe does (its bounds, below: milliseconds where every target is refused, up to the 10 s read bound where a firewall accepts first). A tripwire that passes says its accepted-with-no-answer targets ononNote, not in create'snotes.Targets.
host:portis tried over TCP;host:port/udp(the/udpsuffix, on--connectand in a provider'sprobeTargets) is sent a DNS query over UDP. Modal's and E2B's defaults are TCP to1.1.1.1:443,8.8.8.8:443and[2606:4700:4700::1111]:443, and DNS over UDP to1.1.1.1:53/udpand[2606:4700:4700::1111]:53/udp: DNS over UDP is the classic path out of a sandbox that drops TCP.Each TCP target gets a request by its port, so a server that waits for its client speaks: 443 a TLS 1.2 ClientHello, 80 an HTTP/1.0
HEAD /, 53 a DNS query for example.com (behind its 2-byte length), and any other port an HTTPHEAD /(the most common protocol where the client speaks first; a server that speaks first, as SSH and SMTP do, answers whatever is sent). The ClientHello names the server (SNI) only when the target's host is a name: an IP literal is no server name (RFC 6066, section 3), so1.1.1.1:443gets none. The HTTP request'sHostis the target's host. A UDP target, whatever its port, gets one datagram: a recursive DNS query for example.com's A records with a random id.Bounds: 10 s to connect, 10 s from the request to the answer, at most 4 KiB read per target, every target at once. The probe runs once per create (and per attach and
network(ref)), so its window is wide: a transparent proxy that connects onward lazily, under load, still answers within it. Modal's and E2B's 30 s bound on the probe'sexec.runcovers the longest a probe can take (20 s).Outcomes.
refused: no connection, or for UDP no reply (UDP has no accept, so a datagram that brings nothing back is refused, as is one the far side's ICMP port-unreachable answers).answered: any byte came back, whatever it is: a ServerHello, a TLS alert (a server that will not serve the hello still spoke), an HTTP status line, a DNS response with the query's id and the response bit, a banner, or bytes of no expected protocol (the detail says which; over UDP a datagram that is not the DNS response still came back, and is an answer). Onlyansweredisreached, and a provider refuses network none on any.accepted: a TCP connection, then nothing back within the bound, closed or held open.An accepted-but-silent connection is recorded, never refused and never hidden. Some firewalls accept every outbound connection first and decide after, closing a denied one with nothing sent back (E2B documents exactly this). Such a connection shows that nothing came back, so it is not counted as reached. The provider keeps the computer and names the targets in words: on
onNoteonce a create's tripwire passed, and innoteson whatattachfinds, such asnetwork: none; accepted with no answer (no bytes came back): 1.1.1.1:443, 8.8.8.8:443.network(ref)reads back none. The conformance report carries the provider's notes too, each naming its computer (see Conformance).What the rule can and cannot detect. It detects a TCP or UDP path that carries bytes back within 10 s on a probed host:port. It cannot detect:
- a one-way leak: a path that forwards outbound bytes and drops every reply reads accepted or refused, never answered;
- a port that is not probed: the probe shows its own targets are blocked, not every address;
- a client-first server that silently drops what it is sent: a TCP target whose server waits for its own protocol and
drops a first message it cannot parse (an HTTP
HEADsent to a port that speaks something else) readsaccepted. The defaults never meet this (443 gets TLS, 53 DNS); only an operator's ownprobeTargetscan.
What it changes. Only a provider that probes, on a vendor whose firewall accepts first, reads differently: E2B (below), whose computers with network none the accept-counts rule refused, and are now kept with notes. Docker reads its network back from
docker inspect(--network noneleaves no interface butlo, so a TCP connection is refused outright and a UDP datagram has no route, whichtest/docker/pid1-commands.docker.test.mjspins with the probe itself, every default target refused); Daytona readsnetworkBlockAllback from its API and runs no probe; Modal's live run withblockNetworkread back no TCP accept at any target under the earlier accept-counts rule, so nothing it accepted is newly let through. The UDP targets have not yet run live on Modal.
Processes
A process is a program started under its own guard, as exec.run's are, that keeps running after its call returns.
Its whole tree ends when the program ends or is signalled to its end. Ids are p1, p2, ...; data is base64.
| Method | Params | Result |
| --- | --- | --- |
| process.start | argv, cwd?, env?, user?, pty?: {cols, rows}, stdin?, log?, waitGroup?, orphans?: "keep" | {id, pid}: pid is the program's. cwd, env and user are as for exec.run. Without stdin (and without a pty) stdin is /dev/null. log, waitGroup and orphans are below |
| process.read | id, stream, offset, maxBytes?, waitMs? | {data, nextOffset, dropped, exited, size, capped?, logError?}: stream is stdout or stderr, or pty, or log; at most 512 KiB a call (more is limit); size is the stream's bytes so far, kept or dropped |
| process.write | id, data?, close? | {}: to stdin, or the terminal; close closes stdin after the data |
| process.signal | id, signal | {}: TERM, INT, KILL or HUP, to the program's process group, except INT with a pty (below); to a process that has ended it does nothing |
| process.resize | id, cols, rows | {}: the terminal's new size; the program gets SIGWINCH |
| process.list | from? | {processes, truncated, next}: processes are {id, pid, argv, argvClipped, pty, running, exitCode, signal, startedAt, endedAt} in start order, times in milliseconds since the epoch; at most 768 KiB a reply: when truncated, list again with from set to next. Pages follow start order, not places in the table, so a process dropped between two pages makes the next skip none |
| process.wait | id, timeoutMs | {running, exitCode, signal}: waits up to timeoutMs (0 to a day) for the end, which comes once all the program wrote before it exited is in its log and streams; running is true on timeout |
- Each stream keeps its last 8 MiB in a ring. Offsets count bytes since the process started;
nextOffsetis where the next read starts. A read below the ring's start begins at its start, anddroppedsays how many bytes were lost; an offset past the end isinvalid.exitedis true once the process has ended and nothing is left pastnextOffset. waitMs(at most 30 000) makes a read wait, when nothing pastoffsethas come yet, until bytes come, the process ends, or the time is up. So a client follows a process with one call in flight and no busy loop.- A process whose guard was killed reports the guard's end; one whose guard init's shutdown reaped first reports
KILL. - A listing holds at most 64 KiB of each argv, in JSON. A longer one is listed by its first arguments that fit, with
argvClippedset; the caller that started it has the whole of it. - With
pty, stdout and stderr are oneptystream, and the program runs in a session of its own with the terminal as its controlling terminal (setsid and TIOCSCTTY in the guard). A terminal has no stdin to close: write"\x04"for the end of input, or signalHUP. INTto a process with a pty is ^C: it goes to the terminal's foreground process group, as the terminal driver sends it, so it ends the job a shell runs in the foreground and the shell reads on. The daemon reads that group on the terminal it holds (TIOCGPGRP) and has the guard signal it only when it is in the program's own session (and so under the guard); a terminal the program handed to another session is refused asdenied, and nothing is signalled. The group can end between that check and the signal, and its id go to a group in another session, so the guard checks again right before it signals: a group with no process left in the program's session is not signalled, and the reply saysINTwas not sent:{note}. A terminal with no foreground group left (the program let go of it, or is ending) hasINTgo to the program's group, and the reply says so:{note}.TERM,KILLandHUPalways go to the program's group.- Starts take turns. A
process.startcancelled while it waits for its turn, or before its program runs, isaborted, and nothing it started is left. - Writes to one process take turns. A write waits at most 10 s, its turn included, for the program to read; the rest is
a
timeouterror that says how much was written. A cancelled write, waiting for its turn or writing, isaborted. - The guard keeps no copy of a program's stdin, stdout or stderr pipes once the program runs. So when the program, and
everything it started, have closed stdin (
exec 0<&-), a write fails at once asinvalid, while the program runs on. A terminal is kept open by the guard until the program ends. - The table holds at most 256 processes, running or ended. A start into a full table drops the process that ended
first (its output with it) once the new program runs; a start that is refused drops nothing. When all 256 run, the
start is refused as
limit. - The rings, of running and ended processes alike, hold at most 256 MiB of output together (256 entries' full rings
would be 4 GiB, the default box's memory). Past that, the daemon first lets go of the rings of the processes that
ended first until it is back under. Such a process stays listed with its exit status; a read of its streams returns
no data,
droppedcounts every byte fromoffseton, andexitedis true. When no ended ring is left and running processes still hold more, each running process's ring stops growing and keeps at most an equal share of the budget (never under 64 KiB), dropping its oldest bytes; a read from an offset it dropped reports them indropped. logis an absolute path for a new file the daemon makes and writes the first 16 MiB of the output to, stdout and stderr (or the terminal's) as they come; later output is dropped there while the process runs on. The daemon makes the missing directories and the file itself, never through a link: each directory is entered from the one above it withO_NOFOLLOW|O_DIRECTORY, and the file is made withO_CREAT|O_EXCL|O_NOFOLLOW, mode 0644, the daemon's. A link at the path or at any directory on its way is refused asdenied, a file already there asexists, and the program never starts; a start that fails after the file was made removes it. Thelogstream reads it through the daemon's own open file, never by the path, so a rename or removal under it changes nothing read:sizeis the bytes the log holds,cappedsays output past them was dropped, anddroppedis 0. A write to the log that fails or writes short (a full disk) stops the log for good: nothing after it is written, so the file stays a true prefix of the output, andlogErrorsays why. The log holds all of the output once its stream readsexited; the process's end can come before that.waitGroup: the process runs until its program and every live process left in its process group (with a pty, its session) have ended, and reports the program's own exit. A signal goes once to each process group of the run: the program's, and every other group its live processes are in (a terminal session's jobs), by the group's id. On a pty, the program's exit hangs up the terminal's foreground group, as a terminal does.orphans: "keep": when the process ends, what it started that still runs (a daemon in its own session) is not ended: it runs on under the guard, unsignalled, until it ends or the computer does. Without it, it is ended with the process.
src/processes.ts has readAll(client, id, stream, {offset?, waitMs?, signal?}), which pages a stream by offset
until the process ends and returns its bytes, where it ended and what the ring dropped, and listProcesses(client),
which pages process.list and returns every process.
Files
Every path is absolute, and the daemon cleans it; a relative path is invalid. Files are read and written as the
daemon's user, and data is base64. In a Docker computer that is the computer's user, non-root by default, so it writes
in /work (its home) and /tmp; the image's root-owned directories are denied.
| Method | Params | Result |
| --- | --- | --- |
| files.read | path, offset?, length? | {data, eof, size}: at most 512 KiB a call; a larger length is limit |
| files.write | path, data, offset?, append?, mode?, parents? | {size}: replaces the file unless offset or append; makes it if missing (through a dangling symlink too); mode is set when given (a new file gets 0644); parents makes missing directories |
| files.stat | path, follow? | {type, size, mode, mtimeMs, uid, gid, target?}: type is file, dir, symlink or other; a symlink is reported as one unless follow |
| files.list | path, depth?, offset? | {entries, truncated}: entries carry the stat fields and path, in walk order (by name, a directory before its contents); depth 1 (default) to 16; symlinks are listed, never entered; at most 1000 entries (and 768 KiB) a reply: when truncated, list again with offset plus the entries read |
| files.mkdir | path, parents?, mode? | {}: mode 0755 unless given; a directory already there is exists, or fine with parents |
| files.move | from, to, overwrite? | {}: a rename; without overwrite it never replaces what is at to (exists), checked in the same step as the rename (renameat2 with RENAME_NOREPLACE; a file is linked and unlinked where that is missing, a directory refused); across filesystems is unsupported |
| files.remove | path, recursive? | {}: a directory with entries is is_dir unless recursive; a symlink is removed, never followed; / is denied |
Tar archives move whole trees without holding an archive in memory, and no line passes 1 MiB:
tar.pull.begin {path}returns{id}for the tar of a file (one entry, its name) or a directory (entries relative to it);tar.pull.read {id, maxBytes?}returns{data, eof}, the nextmaxBytes(default and most 512 KiB) of the archive, fewer only at its end;tar.pull.end {id}returns{}, stops the pull and frees it, and may be sent again. The daemon writes the archive only as it is read, so a pull holds at most one read's bytes. Symlinks are archived as links; sockets, devices and pipes are left out. A connection has at most 8 pulls open, and those still open when it ends are ended with it.tar.push.begin {path}makes the directory if missing and returns{id};tar.push.write {id, data}hands it the next bytes (send each after the last one's reply), and extraction runs as they come;tar.push.end {id}returns{entries}. Files, directories and symlinks are extracted with their modes and never chowned; a file gets its header's mtime, as tar gives it (FolderSync.pushinto a synced folder sets 2000-01-01); a directory keeps owner access until the archive ends, then gets its mode, deepest first, whether the push made it or found it. An entry that is absolute, has a..part, or has a symlink or a file on its way isdenied, and ends the push; entries before it stay. A symlink at an entry's own name is replaced, never followed. A file is written beside its target and renamed into place, so a failed or abandoned push leaves no half file. Hard links, devices and pipes areinvalid. A connection has at most 8 pushes open, and those still open when it ends are ended with it.
src/files.ts has the helpers that go past one call: readFile(client, path), writeFile(client, path, bytes) (a
mode is set with the last chunk, so a read-only file over 512 KiB can be written),
pushTar(client, dir, bytes | AsyncIterable<Uint8Array>), pullTar(client, path) (the archive's bytes) and
pullTarStream(client, path, {signal}) ({chunks, done}: one tar.pull.read each time the loop asks for a chunk,
and how the pull ended). Every call is a request and its reply: a slow reader holds back only its own pull, so
pushTar(client, dir, pullTarStream(client, path).chunks) copies a tree on one connection. A push or pull that began
is always ended, whether it finished, failed, was left or was aborted. pushTar owns its source: unless the source is
read to its end, the push calls its return() however it ends, so a pull piped into a push that fails is ended too.
src/tar.ts moves a file's body piece by piece both ways: a TarEntry with size and chunks (an async iterable)
in place of body is written as its chunks come, and fails in words where they end short of size or run past it;
untarPieces(chunks, {take}) gives each file entry with size and chunks in place of body (read them before
asking for the next entry; what is left is passed over). untarStream still gives each entry whole.
FolderSync (the synced folder's delta, src/sync-folder.ts) holds a bounded number of bytes, never a whole folder
or large file. Each file's bytes are held under a grant of a ByteBudget, a semaphore on bytes that every sync in the
process shares (syncBudget, SYNC_BUDGET_BYTES = 256 MiB; new FolderSync(client, sink, {budget}) takes another).
A file up to SYNC_WINDOW_BYTES (16 MiB) is held whole under a grant of its size. A larger one goes to a sink that
has putStream(path, size, chunks) in pieces, under a grant of SYNC_WINDOW_BYTES, and that sink holds at most that
much of it at once and writes nothing at path until every piece has landed. A sink with no putStream is handed
each file whole, under a grant of its size cut to the budget, so that file moves alone. Grants are given first asked,
first given, and no holder asks for a second grant, so a large file is never passed over and no sync waits on another
forever. A large file read again whose size and hash match the last put (the racy rule's re-read, a touch) is
hashed as it is read and put nothing, as a whole one is.
Security
- A push confines every write to its directory at the moment of the write, even while other pushes, or programs in
the computer running as another user, change the tree under it. The daemon opens the directory once and reaches
each entry from that descriptor one name at a time, never following a symlink (
openatwithO_NOFOLLOW,mkdirat,renameat,symlinkat,fchmodon a descriptor). No path is checked and then used by name, so a directory swapped for a symlink between two steps refuses the entry instead of redirecting it. files.write,files.mkdir,files.moveandfiles.removeact on the absolute path the caller chose and make no promise to confine it: they resolve it by name, as any program in the computer would, and follow a symlink on the way. The daemon does not confine them: the container is the only boundary. A provider that runs the daemon as root and programs as a lesser user must confine these calls first. A caller that needs a write held inside one directory against a concurrent actor pushes a tar into that directory.files.read,files.writeand a pull open a file first and then check what they opened (fstaton the descriptor), never a path checked and then opened by name. The open carriesO_NONBLOCK, so a FIFO or a device, there from the start or swapped in by another program, never makes it wait:files.readandfiles.writerefuse it asinvalid(a directory isis_dir), and a pull leaves it out. A pull opens each file withO_NOFOLLOWand writes its tar header from that descriptor'sfstat, so the header matches the bytes it reads; a file that became a symlink is left out too.
src/protocol.ts and daemon/internal/methods are the two definitions of these methods, TypeScript and Go (the Go
params and results of files.* and tar.* sit beside their code in daemon/internal/files).
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.
| setting kind | machine kinds | required groups | optional groups |
| --- | --- | --- | --- |
| none | | | (the run's folder only: no computer) |
| sandbox | linux | exec, files, processes | |
| desktop | desktop | screen, input.pointer, input.keys | exec, files, processes, apps, ui, stream |
| phone | android, ios | screen, input.touch, apps | input.keys, apps.install, ui, stream |
| browser | browser | cdp | stream, downloads |
serves(capabilities, kind)is true whencapabilities().kindis one of the kind's machine kinds and every required group is declared, so a provider that drops a group stops serving the kind;servingRefusalssays why not in words, andkindOfnames the setting kind capabilities serve (machine kinds are apart, so at most one).PROVIDERSis what Settings offers: each entry'sid,label,keys(the serve-side names Settings accepts, each required or not; never a value),mounts(the mount kinds its computers take;[]cannot mount the run's folder),metered(the vendor bills by time), andcapabilities, the machine kind and groups of each configuration it offers. Itskindsare derived from those byserves, never written by hand.An entry's
defaultImagenames the image a computer of each setting kind starts from when its setting names none, each the constant its provider module owns. A kind with no entry has no default, and the caller refuses the setting in words. Docker has none: serve builds its image itself.| id | defaultImage | | --- | --- | | docker | none | | daytona | sandbox:
DAYTONA_DEFAULT_SNAPSHOT("default") | | modal | none:prepareImage()answers the box image (boxImageRef()) | | e2b | none:prepareImage()answers the box template (boxE2bTemplate()), for a sandbox and a desktop alike | | smolcloud | none:prepareImage()answers the box image (boxImageRef()) | | vercel | none:prepareImage()answers the box image's tag in the project's registry (boxVercelImage()) | | orgo | desktop:ORGO_BASE_IMAGE("linux") | | phone-harness | phone:PHONE_IMAGE("android") | | browserbase, kernel, local | browser:BROWSER_IMAGE("chromium") || id | label | kinds | keys (required unless marked) | mounts | metered | | --- | --- | --- | --- | --- | --- | | docker | Docker | sandbox, desktop | none | bind | no | | daytona | Daytona | sandbox |
DAYTONA_API_KEY;DAYTONA_API_URL,DAYTONA_TARGET,DAYTONA_ARCHIL_EGRESS,DAYTONA_ATTACH_EGRESS,DAYTONA_PUBLIC_EGRESS,DAYTONA_LISTED_MS,DAYTONA_WARM_POOL(optional) | none (unmounted: archil); archil withDAYTONA_ARCHIL_EGRESS(mountsWith) | yes | | modal | Modal | sandbox |MODAL_TOKEN_ID,MODAL_TOKEN_SECRET| archil | yes | | e2b | E2B | sandbox, desktop |E2B_API_KEY;AGENTRUN_E2B_DOMAIN,AGENTRUN_E2B_API_URL,AGENTRUN_E2B_TEMPLATE(optional) | archil | yes | | orgo | Orgo | desktop (Linux; Windows and macOS withos) |ORGO_API_KEY| none | yes | | phone-harness | Phone harness | phone |PHONE_HARNESS_API_KEY| none | yes | | browserbase | Browserbase | browser |BROWSERBASE_API_KEY,BROWSERBASE_PROJECT_ID| none | yes | | kernel | Kernel | browser |KERNEL_API_KEY| none | yes | | local | Local Chrome | browser | none | none | no |A provider's capabilities and mounts are its descriptor's, and nowhere else. A unit test holds each provider built from the test fakes, in each configuration, to its entry's capabilities and mounts. browserbase and kernel are data until their provider file joins the registry; that test then holds each to its file.
testConnection()(optional onComputerProvider) is Settings' test of a provider's keys: ONE account-level read that never creates a computer, so it never spends. Docker (onedocker ps), Daytona and E2B (one listing page) count the provider's own computers by its label from that one answer, never reading each back, so a busy account answers as fast and one computer's read never fails a working key; a further page reads "or more". Orgo reads its workspace's computers; Modal reads its app without making it (an app not made yet is still a connection). It answers{ detail }in words, or an error:unauthorizedfor a key the vendor refused,unreachablefor a vendor not reached in time, else the read's own code; no message carries a key. A full live check (create, then the kind's conformance) is the QA board's.TestConnectionis the serve side's signature,(providerId, { keys, signal }), keys by their serve-side names.A browser computer's connection carries
cdp: { url }, its CDP target: a secret, never logged and never in a result, a report or an error.A provider passes a setting kind's conformance with
--kind(see Conformance).
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.
Kind. capabilities().kind is "linux" | "desktop" | "android" | "ios" | "browser", and hello repeats it. os stays: it names
the platform the key table and exec need; kind names the shape the tools need. Only these pairs are valid
(kindRefusals(capabilities) names any other in words, and the case health.kind-consistent fails it):
| kind | os | daemon | Core groups, besides health, provider and drift |
| --- | --- | --- | --- |
| linux | linux | pid1 or child | exec, files, processes; network none |
| desktop | linux (windows, macos later) | pid1, child or none | linux's, when daemon is not none; and screen, input.pointer, input.keys |
| android | android | none | screen, input.touch; exec and files only when declared |
| ios | ios | none | screen, input.touch |
| browser | linux | none | cdp: its connection's CDP target (see Browsers) |
The groups cdp, stream and downloads are the provider's (PROVIDER_GROUPS): a browser's CDP target, a live view of
the screen (provider.stream()), the files a browser saved. A computerd hello never lists them.
Daemon mode. capabilities().daemon says who answers the methods. pid1: computerd init is the computer's main
process, so its exit ends the computer (Docker). child: the vendor's own agent is the main process and starts init at
boot; init's exit does not end the computer (Daytona, whose toolbox daemon starts init detached), and it
must not run under a supervisor that restarts it. none: no computerd runs, and the provider answers the same methods
itself, from our server (adb, a vendor API). Either way a connection's client is a ComputerClient (call(method,
params, { signal }) and close()): DaemonClient over a stream, or a provider's in-process client.
Groups. capabilities().groups is one flat list, repeated in hello's groups: exec, files, processes,
screen, input.pointer, input.keys, input.touch, apps, apps.install, ui, and the provider's
cdp, stream, downloads. Each is optional unless kind makes it Core. The drift check and Docker's connect refuse a hello whose kind or groups differ from what the
provider declares, either way.
| group | methods |
| --- | --- |
| screen | screen.shot({ region? }): a PNG (8-bit, non-interlaced), its first MAX_CHUNK_BYTES in data, with width, height (the image's pixels, the input coordinate space, never downscaled), scale and cursor?; screen.read({ id, offset }) for the rest. One shot is held, until its eof or the next shot. screen.watch({ after, waitMs?, maxWidth?, quality? }): the live view's frames, paced by the caller's ack (after, the seq of the last frame it has whole; an older one gets the newest frame at once; on a computer whose hello lists screen.ahead, one past the newest waits as the newest does, so two asks can be in flight): the next frame once the screen or the pointer changed, else changed: false when waitMs (default 2000, at most 10000) is over. Computerd on a desktop learns what changed from the X server's DAMAGE extension and gives at most 15 frames a second; on an X server without DAMAGE, screen.watch is refused, unsupported, in words. A frame is { seq, changed, format, frameWidth, frameHeight, width, height, cursor? } and its bytes as a shot's (data, id and screen.read); format is jpeg from computerd and from phoned (scaled to maxWidth, default 1280, at quality, default 60); phoned reads the phone's screen at most every 200 ms while a watch waits, and encodes only a changed one, and the phone-harness provider's watch asks 720 wide when its caller names no width. One watch per connection. |
| input.pointer | input.actions: move, down, up, click (count 1-3, held keys), drag (a path of 2 or more points), scroll (unit clicks or px) |
| input.keys | input.actions: key (one key pressed, or a combo released in reverse; repeat), hold (ms), type |
| input.touch | input.actions: tap, long_press, swipe, pinch (scale above 1 apart, below together), button (back, home, app_switch) |
| apps, apps.install | apps.list ({ apps, foreground }), apps.launch({ id, url?, background? }), apps.terminate; apps.install({ path }) of a file already in the computer |
| ui | ui.observe({ target?, full?, image?, since? }): { state, app, window, nodes, diff?, image?, truncated }, at most 5000 flat nodes, each { ref, role, name?, value?, id?, bounds, parent?, flags?, actions? } with an ARIA role and bounds in window points. ui.act({ target?, state?, steps, expect?, foreground? }): { steps, state?, window?, changed, expect? }, each step's route and verified, or its refusal (stale, denied, ...) as the last; window: "closed" in place of state when the app has no window left. expect is { text?, ref?, gone?, timeoutMs? }, or { window: { title?, role? } } to wait for a window. The rules are in wire.md; UiEngine (src/ui-engine.ts) keeps them over a UiSource, UiSession (src/client.ts) is the typed caller, and @parcha/agentrun-computer/fake-ui-driver answers them from scripted apps for tests |
The live view's seam (src/screen-watch.ts). The runner's viewer reads a computer through
provider.watch?(ref, handlers, { signal?, maxWidth?, quality? }):
handlers.frame(frame, ack)gets each wholeScreenFrame({ seq, format, bytes, width, height, frameWidth, frameHeight, cursor? }), and the next frame is asked for only onceack()is called.widthandheightare the screen's real pixels, the input space; onlyframeWidthandframeHeightscale tomaxWidth.handlers.ended(error)is called once if the computer goes, with the codegone,unreachable,refusedorunsupported, in words with no URL.close()and the signal end the watch with noended().- The answer's
input(actions)sendsinput.actionson the watch's own connection, andclose()lets that connection go. After the end,input()refuses in words.
daemonWatch is the one implementation behind every provider's watch() (Docker, Daytona, Modal, E2B, Orgo, the
phone harness): a computer whose hello has no screen is refused as unsupported. It adapts the internal seam,
watchScreen(connection, options): pull-paced frames (each next() the ack), act(actions) and close(), whose
failures are ScreenWatchErrors. On a computer that lists screen.ahead it keeps a second ask in flight, one frame
ahead, so frames come at the screen's pace and not one each round trip; a frame bettered before next() asked for it
is dropped. toAction(event, kind) maps the viewer's ViewerEvents, in the screen's upright
pixels, to input actions, or to a Refusal ({ field, message }) for what a kind cannot take:
- a desktop takes the mouse (a move, and a button down or up at a point; with a modifier held, the up is one click
with its keys and the down only moves; each up is one click, so a double-click is two and never a
count), the wheel (in clicks, about 120 px a notch, 20 clicks at most an event), keys (combos with the modifiers held, Shift kept: ctrl+shift+s) and typed text; never ctrl+alt+backspace or ctrl+alt+F1 to F12, which end or switch the X display; - a phone (
android,ios) takes taps, swipes (0 to 1000 ms, clamped), back, home and recents (app_switch), keys and typed text; - a typed text holds 65,536 characters at most (
checkActionsrefuses more aslimittoo, as computerd does); - anything else, and an event whose fields are not what its type says, is refused in words:
toActionnever throws.
toAction is stateless. A viewer maps through createActionMapper(kind), one per take-over: its map(event) answers
as toAction does, but a desktop's mouse press decides the strategy for the press and its release together (a
modifier let go before the up still clicks once, with the keys held at the down; a plain press stays plain), and its
release() gives the ups for every button it pressed and has not released, then forgets them (on blur, or when the
take-over ends). No key is ever among them: the protocol presses and releases a key within its action.
The seam reads a frame by the size it says (never past it, never over 64 MiB, and whole at the end), keeps 8 inputs
in flight at most on a watch (one more is refused as limit), and redacts every error and a failed action's words
(redactWords: URLs, logins, bearers, secret-named parameters, key and token shapes, and host or IPv4 endpoints).
No error in this seam holds a URL or a secret (redactWords). A phone's frames are upright with no rotation of ours:
screencap gives the display in its current orientation, and input tap takes the same space.
Points are [x, y] in the full screenshot's pixels, origin top left; a region shot never changes that space. A key is a
name in KEYS (enter, tab, space, backspace, delete, escape, insert, the arrows, home, end, pageup, pagedown, f1-f12,
shift, ctrl, alt, super, capslock) or one printable ASCII character (0x21-0x7e); the daemon's Go table
(daemon/internal/keys) mirrors it, and a Go test keeps the two equal.
Model vocabularies (Anthropic's Return or ctrl+s, OpenAI's keypress) are mapped to these by a tool adapter on the
server, once per model family, never per vendor.
input.actions rules: the whole batch is checked first (its shape, at most MAX_ACTIONS = 100 actions, every key
against KEYS, each action's group against what is declared, a px scroll where only clicks exist, and wait plus hold at
most MAX_BATCH_WAIT_MS = 300 s); a failure returns { done: 0, failed: { index, kind, message } } and nothing runs.
checkActions(actions, groups, { pixelScroll? }) is that check, for an implementer, an early caller, or an in-process
client. Then the actions run in order and stop at the first failure (a point off the display, a display gone) with
done = its index, and every button and key the batch pressed and did not release is released. A success keeps state:
a down with no up stays down into the next batch. A cancel stops before the next action and releases as a failure
does.
Lifetime. capabilities().maxLifetimeMs is the vendor's hard cap for the provider instance (Docker: 30 days).
checkLifetime(lifetimeMs, capabilities) is the one rule every check() shares: a whole number of milliseconds above
0, at most the cap, refused in words with no vendor call. A provider may offer `extend(ref, ttl
