# Remote hosts

A host is a machine that runs jobs for this one. Nothing is installed on it for fleetjobs: this machine sends a small script with each call, and the host runs it with Node.

## What a host needs

| Tool | Why |
| --- | --- |
| `ssh`, with a key and no password prompt | Every call uses `BatchMode=yes` and a 4-second connect timeout |
| `node`, 22.20 or later | Runs the host script |
| `rsync` | Copies the checkout in and the files the job wrote back |
| `bwrap` (bubblewrap) | Runs the job with the mirror mounted at the checkout's own path |
| `git`, the package manager and the tools your jobs use | The host installs dependencies and runs the command |

Without `bwrap`, the job still runs, but the mirror sits at a different path than your checkout, so absolute paths in configs and output differ.

This machine needs `ssh` and `rsync` too, and Linux with systemd for [local scopes](https://fleetjobs.loadsheet.dev/guide/placement#when-memory-runs-out).

## Add a host

Add it to `~/.config/fleetjobs/config.json`:

```json
{
  "hosts": [{ "name": "build-box", "address": "me@build-box", "slots": 2, "speed": 0.5 }]
}
```

`address` is what you would pass to `ssh`. `slots` is how many jobs the host runs at once, and `speed` is its speed against this machine, where `1` is as fast. fleetjobs reads the file on every tick, so there is nothing to restart. See [the config reference](https://fleetjobs.loadsheet.dev/reference/config).

Check the host from this machine with `ssh me@build-box node --version`. Then run a test job: `HEAVY_REMOTE=1 heavy sh -c 'echo ok > out.txt'`. When the host finishes first, `heavy` prints the line `this runs on build-box` on stderr, and `out.txt` appears here.

## What a run does

1. **Probe.** The host reports its free slots and whether it is busy. It is busy under 3 GB of free memory, under 15 GB of free disk, or when CPU pressure is 40% or more while other processes use 25% or more of the CPUs. CPU used by fleetjobs' own jobs is subtracted. A host may change these limits with `HEAVY_HOST_MIN_MEM_GB`, `HEAVY_HOST_MIN_DISK_GB` and `HEAVY_HOST_MAX_OTHERS` in its environment.
2. **Copy.** rsync copies the checkout, with uncommitted changes, to `~/overflow/mirror<checkout path>` on the host. It leaves out `node_modules`, `.git`, `.env` files, `.pem` files, and what git ignores, except `dist` and `.nuxt`.
3. **Install.** The host installs dependencies once per hash of the lockfiles and package manifests, with `pnpm install --frozen-lockfile` or `npm ci`.
4. **Run.** The job runs under `nice` and `bwrap` in a slot of the host, `~/overflow/heavy-slot-<n>`, and stops if the connection drops. Output streams back as it comes, and `HEAVY_MAX` applies.
5. **Copy back.** The host lists each file the job wrote with its SHA-256, and rsync copies them to this machine, where fleetjobs checks each one. A copy that fails or does not match turns exit 0 into exit 74.

## Exit codes of a host

| Exit | Meaning |
| --- | --- |
| 200 to 205, 208, 255 | The job did not start: the host is busy or has no free slot, the mirror is missing, the install failed, the copy failed, or ssh could not connect. The host rests for a minute and the job goes back to the queue here |
| 206 | The output shows what the mirror lacks, such as `not a git repository`. The job runs here, ahead of the queue |
| 124 | The job passed `HEAVY_MAX` |
| 74 | The job passed, but the files it wrote did not come back intact |

Any other code is the job's own. What happens to a failing job is in [Trust](https://fleetjobs.loadsheet.dev/guide/trust).

<!-- vitehub-docs:section-links -->
## In this section

- [Introduction](https://fleetjobs.loadsheet.dev/raw/guide.md)
- [Installation](https://fleetjobs.loadsheet.dev/raw/guide/installation.md)
- [How jobs are placed](https://fleetjobs.loadsheet.dev/raw/guide/placement.md)
- [Remote hosts](https://fleetjobs.loadsheet.dev/raw/guide/hosts.md) (this page)
- [Trust](https://fleetjobs.loadsheet.dev/raw/guide/trust.md)
- [Night queue](https://fleetjobs.loadsheet.dev/raw/guide/night.md)
- [Migrating from the bash heavy](https://fleetjobs.loadsheet.dev/raw/guide/migrating.md)
- [For agents](https://fleetjobs.loadsheet.dev/raw/guide/agents.md)

Next: [Trust](https://fleetjobs.loadsheet.dev/raw/guide/trust.md)

All pages: [llms.txt](https://fleetjobs.loadsheet.dev/llms.txt)

Something on this page does not work as written? Tell the user, and draft an issue for them to post: [issue tracker](https://github.com/words-with-agents/fleetjobs/issues). Report a security vulnerability privately, never in a public issue.
