A runner runs the repository’s own program for each job, .forge/test for a check, as code under test: it may be wrong or hostile, and it must not be able to change the code it tests, the runner, or the machine. So each job runs in a sandbox of its own, built by the runner’s own binary from Linux’s own parts, as bubblewrap and nsjail build theirs. There is no container runtime or virtual machine to install.
What the program sees
| Path | What it holds |
|---|---|
/work/src |
The commit’s files, read-only. It is the program’s working directory. |
/work/forge |
main’s .forge/ folder, read-only, as it is at the job’s commit of main. The program is /work/forge/test, or release for a release’s build. |
/work/changed |
Every path the commit changes from its parent, one a line, read-only. |
/work/out |
An empty directory it may write, such as for build outputs. A release’s build leaves its artifacts here. |
/work/home |
An empty directory it may write, its HOME. |
--system paths |
The host paths the runner was started with, at the same paths, read-only. |
/tmp |
An empty in-memory directory it may write. |
Its environment is only the runner’s --env variables and the job’s own: FORGE_COMMIT, FORGE_BASE and FORGE_TESTS_AT, the commits involved, each in hex, and FORGE_OBJECT_FORMAT, the hash that names them (sha256 or sha1); FORGE_CHANGED and FORGE_OUT, the paths above; HOME; and the build cache’s two addresses. A check passes by exiting 0 with every test it listed reported under /work/out/tests and none failed, and a release’s build by exiting 0. Testing and landing shows a test program.
How it is built
The runner starts its own binary as the sandbox’s setup, as runc starts runc init, and gives it the sandbox’s description, the program’s environment among it, through an anonymous in-memory file that is sealed against writes: the setup reads it and closes it before the program runs. Nothing of it is in the setup’s arguments, so no process of the same user can read an environment value, such as an operator’s key, from /proc/<pid>/cmdline, and a description larger than a pipe’s buffer or an argument list reaches it all the same. The setup:
- Makes a user namespace that maps only the runner’s own user and group, and with it new mount, process, network, IPC, host name and cgroup namespaces. The program runs as the runner’s own user, never with more, so run the runner as an ordinary user of its own.
- Starts a first process that reaps every other, and builds the file tree: an empty root holding only what the job binds, each read-only unless the table says otherwise; a fresh
/proc; a/devof onlynull,zero,full,random,urandomandtty; and an in-memory/tmp. It then moves into that tree, leaves the host’s behind, and makes the root itself read-only. The network namespace holds only loopback. - Starts the program, which drops every capability, can gain none (
no_new_privs), is held by Landlock to writing only the writable paths,/tmpand/dev, and by a seccomp filter to the system calls Docker’s default profile allows. Only then does the program run, with only the environment above.
When the program ends, so does everything it started: the reaper ends with it, and its namespaces with the reaper. Stopping the runner stops every sandbox.
The program’s exit status is the job’s result. Two statuses belong to the sandbox, as docker run’s do: 125, it could not be set up, and 127, the program could not be started. A sandbox that cannot be set up is the runner’s fault, not the change’s: the runner reports no result, hands its jobs back, and stops.
The agent sandbox
An agent runner starts a harness, a third party’s program that drives a model, in a sandbox built the same way, and holds it to more. The runner has all of it built and tested; the agent mode that starts a harness with it is not built yet, so a check or a release’s build does not use the limits below.
| What | What the harness has |
|---|---|
| Environment | Only the names its adapter’s record lists, with the operator’s values, HOME, NO_PROXY=127.0.0.1,localhost, and HTTPS_PROXY and HTTP_PROXY, which name the runner’s proxy. A proxy variable in a record is dropped, in any case. |
| Home | A copy of the operator’s template (--harness-home NAME=DIR), made for the step in an in-memory directory of mode 0700 and a bound size, so the harness’s own login is there to use. The step changes its copy and never the template; the copy goes with the step and is never on the runner’s disk. A template that does not fit ends the step and names the file. |
/tmp, /dev/shm |
In-memory, of at most --step-tmp-max (1 GiB), mounted nosuid and nodev. |
| Network | Loopback and nothing else. There is no network to send a lookup over, so DNS carries nothing out. |
The proxy
The one way out is the runner’s proxy, served by the runner outside the sandbox on a loopback address inside it. It takes CONNECT host:443 and no other request: a request for another port, a plain GET, a head that two parsers could read two ways, or bytes sent behind the head are each refused. The host must be an exact name on the allowlist, its adapter’s hosts and its kind’s; names are compared in lower case with one trailing dot stripped, and an authority with user information, a space, a % or a bracket outside an IPv6 literal is refused.
It resolves the name itself, once, and requires every address the answer holds to be public. It then dials the first of those exact addresses and never the name again, so a name that answers a private address the second time cannot be rebound. Public excludes this network, private use, carrier-grade NAT, loopback, link-local (the cloud metadata service at 169.254.169.254 among it), multicast, the documentation and reserved ranges and all of IPv6 outside global unicast; an IPv6 address that carries an IPv4 one, IPv4-mapped, NAT64 (64:ff9b::/96), 6to4 and Teredo, is judged as the IPv4 address it carries. A raw IP address in the request is refused. A connection has ten seconds in all to send its head, not ten seconds a read, and a session holds at most sixteen connections that have not yet sent one, so a harness cannot use up the runner’s descriptors with connections that never ask for anything. What the proxy refuses it counts, per agent and host, for at most 64 hosts and the rest together as other.
--allow-network CIDR, which may be repeated, is the one way past the address rules: an allowed name may then answer inside that network, and a raw address in it may be asked for. It refuses a prefix of /0, which would be no rule at all, and nothing else turns the proxy off.
What it is held to
A sandbox of this kind is only as good as what it leaves open. These limits are taken from the ones Box, the sandbox of AWS’s Strands Agents, states of itself, and from the escape hatch no such sandbox may have silently.
| A known limit | What the runner does |
|---|---|
A broad read grant reaches the operator’s ~/.ssh and ~/.aws |
At start the runner refuses a --system path or a harness-home template that is, is inside, or holds .ssh, .aws, .gnupg, .kube, .docker, .config/gcloud, .netrc or .git-credentials of any home on the machine, or that is or holds a home itself, even one that has no credential in it yet, and looks two levels down in a folder it does not know to be a home. The sandbox shows none of the operator’s dotfiles. |
| A descriptor the parent left open reaches the program | Before it does anything else the sandbox’s setup closes every descriptor above the three standard ones, but the sockets of the endpoints it was given, so a descriptor of a host directory that the runner’s parent held open is not the harness’s. |
| A long-lived connection outlives the policy that opened it | A tunnel is closed at --tunnel-max-seconds (one hour), and a session holds at most --tunnels-max (32), the next CONNECT refused and counted. |
| An escape hatch that turns containment off | There is no option for it. --allow-network is named in the help, and is the only way past the address rules. |
What a step may use
An agent runner limits each step’s memory (--step-memory-max, 4 GiB, swap off, the step ended whole when it outgrows it), processes (--step-pids-max, 512) and CPU (--step-cpus) with a control group the operator delegates to it, and refuses to start in agent mode without one: run it as a systemd unit with Delegate=yes, or under systemd-run --user --scope -p Delegate=yes. A fork bomb ends the step alone. Disk is --step-disk-max (4 GiB) of the step’s directory, watched, and the in-memory directories’ own size.
The watcher cannot see everything. A watcher that walks a directory counts the files it finds, and cannot see the bytes of a file a program opened and then unlinked, which it can keep writing. The limit that holds is the in-memory directory’s size, which counts those bytes, and, on a filesystem with project quotas, the quota; the book says so rather than count on the watcher. The walk goes by directory descriptors and follows no link: a folder the step swaps for a link while the walk is at it is skipped, never read, and one the step took its rights from is given them back through the folder itself and not through its name, so the step cannot point the walk, or a change of rights, at anything outside its directory. A tree more than 128 folders deep counts as past the budget.
A runner that has had no confirmed heartbeat for the TTL it was told plus the forge’s grace ends its sessions itself, and says so when it reconnects.
Not yet
- No limits on a check’s or a release’s program on time, memory, processes or disk: it can run as long and use as much as the machine allows. An agent’s step has the limits above once agent mode is built.
- A program cannot make a sandbox of its own, as Docker’s default profile also forbids, so a test suite that needs nested containers does not run here.
- No network for a check or a release’s build but loopback, and the build cache the runner serves inside it.
- The step’s
/tmpcan run programs. It is mountednosuidandnodevbut notnoexec: whether the harnesses still run with it is measured with them.
Next
- Jobs and results: how a job reaches the runner and its result reaches the forge.
- Build caches: the caches a job’s build can read and write.