---
title: "Set up a runner"
description: "Make a runner's key on its machine, have an administrator enroll it, and start it. The forge then pushes it checks to run, each in a sandbox of its own."
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.forge.workreef.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Set up a runner

A runner is a machine that runs the forge's jobs: the checks that gate each change before it lands, the tests of `main` after, and release builds. Only a runner's checks gate a landing. A runner is born from the forge when an administrator enrolls it, so it is never in the line of the person or agent whose change it tests.

Setting one up takes three steps: make its key on the machine, have an administrator enroll the key, and start it. A machine that hosts agents is another thing, an [agent runner](https://docs.forge.workreef.dev/runner/agent-runners/).

## Make the runner's key

On the runner's machine, `af-runner key` writes a new Ed25519 private key, readable by its owner only, and prints the public key. The private key never leaves the machine. Start a development forge to follow along:

```console server
$ af-server --dev
...
```

```console check
$ source ~/af-dev/dev/env
$ af-runner key ~/runner.key | tee ~/runner.pub
636e5f0a80d6fff5765d15bf7e99520ed9c171a88ec517f60f213a68e4f051d1
```

## Enroll it

An administrator enrolls the public key with a name for the machine. The enrollment takes effect at once, on their word, unless the forge requires a second administrator to approve it. The ID it prints is the runner's:

```console check
$ af enroll-runner "$(cat ~/runner.pub)" --name build-01 | tee ~/runner.id
done: it took effect at once, on your word as an administrator
born 61b8d07ee35f03cce902027457be24187788fd8ecfc198631df334bb9fb04263
```

## Start it

`af-runner run` connects to the forge with the runner's ID and key and runs the jobs it is given, until it is stopped:

```console nocheck runs until it is stopped, so it goes in a terminal of its own
$ af-runner run --address forge.example.com:7777 \
>     --id 61b8d07ee35f03cce902027457be24187788fd8ecfc198631df334bb9fb04263 \
>     --key ~/runner.key --work /var/lib/af-runner \
>     --system /usr --system /bin --system /lib --system /lib64 --capacity 4
af-runner: 61b8d07ee35f03cce902027457be24187788fd8ecfc198631df334bb9fb04263 runs up to 4 jobs at once
```

Its options:

| Option | What it sets |
| --- | --- |
| `--address` | The forge, as host and WebSocket port. The runner connects over WebTransport where it can, and `--websocket-only` keeps it to WebSocket where UDP does not reach the forge. `--cert-hash` pins a self-signed certificate, as `af --cert-hash` does. |
| `--capacity` | How many jobs it runs at once. The forge pushes it a job whenever it holds fewer. |
| `--work` | Where each job's files go while it runs. Each job has a directory of its own, removed when it ends; whatever an earlier run left there is removed when the runner starts. |
| `--system` | A host path a job's program may read, at the same path, read-only: the toolchain and the libraries a build needs. Repeat it for each path. A symlink, such as `/bin` where it points into `/usr`, is seen as the same symlink. |
| `--env` | A variable for the programs, as `NAME=value`. Repeat it for each. A program sees no other variable of the runner's. |

What a job's program sees, and what it cannot do, is on [the sandbox](https://docs.forge.workreef.dev/runner/sandbox/) page.

> **On a development forge**
>
> A runner has work only once `main` holds a test program, `.forge/test`, and a change that edits `.forge/` needs a person's approval, its author's included unless the forge requires another person. A runner started against a development forge connects and waits, and is given a job once such a change has landed.

## Stop it

`af-runner run` stops on an interrupt or `SIGTERM`. It first hands its unfinished jobs back to the forge, which gives them to other runners at once. If its connection drops instead, or a node of the forge restarts, the runner connects again and goes on with the jobs it holds; they stay its own while [its lease](https://docs.forge.workreef.dev/runner/jobs/#leases) holds.

An administrator can stop a runner for good with `af stop`, which refuses it from then on. `af-runner run` exits when the forge refuses it:

```console check
$ af stop "$(sed -n 's/^born //p' ~/runner.id)" --reason "machine retired"
stop reference ad484b0dbd10c85ab5dde011db61fe3b4675c0bfc1c91c64b8a32a9dd12f5afc
stopped 61b8d07ee35f03cce902027457be24187788fd8ecfc198631df334bb9fb04263
```

## Next

- [From a test to a release](https://docs.forge.workreef.dev/runner/end-to-end/): one runner, end to end, on a development forge.
- [The sandbox](https://docs.forge.workreef.dev/runner/sandbox/): what a job's program sees.
- [Jobs and results](https://docs.forge.workreef.dev/runner/jobs/): how work reaches runners, and how a result becomes a record.
- [Build caches](https://docs.forge.workreef.dev/runner/cache/): Gradle's and sccache's caches, served to each job.
- [`af-runner`](https://docs.forge.workreef.dev/reference/af-runner/) and [`af enroll-runner`](https://docs.forge.workreef.dev/reference/af/enroll-runner/) in the reference.

Source: https://docs.forge.workreef.dev/runner/setup/index.mdx
