# Set up a self-hosted runner

Create a runner pool, install kosem-runner on a Linux host or Apple silicon Mac, and run agents and environments on it.

Create a runner pool, register a Linux host or Apple silicon Mac, and run environments on it. Creating pools and adding runners requires Owner, Editor or Environment Admin on the organization (for shared pools) or on the project (for a project pool). Sharing an organization pool with projects requires Owner on the organization.

## Before you start [#before-you-start]

Check your organization's **Self-hosted runners** quota ([Limits and quotas](/reference/limits#environments)). Keep Linux x86_64 hosts and Apple silicon Macs in separate pools, because every runner in a pool must share one architecture.

- **Linux:** x86_64 (`amd64`) with `/dev/kvm` (bare metal, GCP `--enable-nested-virtualization` or AWS C8i, M8i or R8i with nested virtualization), cgroups v2 at `/sys/fs/cgroup`, `curl`, `tar`, `losetup`, `nft`, `systemctl`, `sha256sum`, `sudo` and outbound HTTPS to `https://api.kosem.ai` and your container registries.
- **macOS:** Apple silicon (`arm64`) with macOS 26 or later, Apple's `container` CLI 1.6.1 or later (`brew install container`, or [apple/container releases](https://github.com/apple/container/releases)) and outbound HTTPS to `https://api.kosem.ai` and your container registries.

## Create a runner pool [#create-a-runner-pool]

Create a pool in your organization to share hosts across projects, or in a project for that project only.

1. In your organization or project, click **Environments**, and then **Runners**.
2. Click **New pool**.
3. Enter a **Name**, such as `Build hosts`.
4. On an organization, if you're an Owner, select **All projects**, **Selected projects** or **No projects** under **Projects that can use this pool**.
5. Click **Create pool**.

Organization pools shared with a project also appear under **Shared by …** on that project's **Runners** page.

## Add and install a runner [#add-and-install-a-runner]

1. Beside the pool, click **Add runner**.
2. Enter a **Name**, such as `build-01`, and click **Add**.
3. Select **Linux** or **macOS** and copy the command. The registration token (`krt_…`) expires after 1 hour and isn't shown again.
4. Click **Done**, then run the command on your host:

```sh
# Linux (run with sudo)
curl -fsSL https://api.kosem.ai/v1/runner/install.sh | sudo bash -s -- \
  --url https://api.kosem.ai \
  --token krt_…

# macOS (run as your user, without sudo)
curl -fsSL https://api.kosem.ai/v1/runner/install.sh | bash -s -- \
  --url https://api.kosem.ai \
  --token krt_…
```

- **On Linux**, the installer downloads `kosem-runner` plus its isolated `containerd`, Kata Containers and CNI bundle (verifying each SHA-256), sets up `nftables` isolation on bridge `kosem0` (`10.89.0.0/24`), links `/usr/local/bin/kosem-runner`, registers the host and starts the `kosem-runner-containerd` and `kosem-runner` systemd services.
- **On macOS**, the installer starts `container` if stopped, downloads and registers `kosem-runner`, asks for your password once to load `pf` firewall rules and link `/usr/local/bin/kosem-runner`, and installs the `ai.kosem.runner` LaunchAgent so it starts when you sign in.

Within a few seconds, the runner changes from **Not registered** to **Online**.

## Run an agent on the pool [#run-an-agent-on-the-pool]

1. In a project that can use the pool, open **Agents** for a new agent or an existing agent's environment settings.
2. Under **Runs on**, select your runner pool.
3. Under **Environment image**, select an image for the pool's architecture (`linux/amd64` for Linux, `linux/arm64` for macOS).
4. Start the agent or send a message.

On an existing agent, changing **Runs on** deletes its previous environment and disk and creates a fresh environment in the selected pool on its next command. To check where any environment runs, open it under **Environments** and read **Runs on** under **Configuration**.

## Customize host limits and installer options [#customize-host-limits-and-installer-options]

Append options after `--token krt_…`. The installer saves them in `install.conf` and reapplies them on upgrades:

| Option                                                | Platform     | What it sets                                                                               |
| ----------------------------------------------------- | ------------ | ------------------------------------------------------------------------------------------ |
| `--max-vcpus`, `--max-memory-gib`, `--max-disk-gib N` | Linux, macOS | Caps on vCPUs, memory (GiB) and disk (GiB) offered to environments                         |
| `--subnet CIDR`                                       | Linux        | Bridge subnet for environments (default `10.89.0.0/24`)                                    |
| `--bin-dir DIR`                                       | Linux, macOS | Directory for the `kosem-runner` symlink (default `/usr/local/bin`)                        |
| `--no-firewall`                                       | macOS        | Skip `pf` firewall rules so installation needs no `sudo`                                   |
| `--replace`                                           | Linux, macOS | Uninstall an existing runner (deleting its environments and disks), then install a new one |

:::warning
On macOS, `--no-firewall` lets environments reach services on your Mac and local network. Skip `pf` rules only when you isolate the network another way.
:::

## Set up with the API [#set-up-with-the-api]

Set your API key ([Call the API](/get-started/call-the-api)), organization ID and project ID, then create an organization pool shared with all projects (project pools use `/v1/projects/$KOSEM_PROJECT/runnerPools` without `availability`):

```sh
export KOSEM_API_KEY='kosem_sk_…'
export KOSEM_ORG='org_01m5r8w2k3e9vbt6g0d4x7qz1h'
export KOSEM_PROJECT='prj_01m5r9dh9mf0ps98ktkap3562c'

curl -s -X POST "https://api.kosem.ai/v1/organizations/$KOSEM_ORG/runnerPools" \
  -H "Authorization: Bearer $KOSEM_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"displayName": "Build hosts", "availability": {"allProjects": true, "projects": []}}'
```

Save the pool ID (`rnp_…`) from `name`, create a runner to receive its one-time `registrationToken`, and once the host is `ONLINE`, pass `runnerPool` when creating an environment (or inside `config.environment` for an agent):

```sh
export KOSEM_POOL='rnp_01m5rh2kq2e9vbt6g0d4x7qz1t'

curl -s -X POST "https://api.kosem.ai/v1/organizations/$KOSEM_ORG/runnerPools/$KOSEM_POOL/runners" \
  -H "Authorization: Bearer $KOSEM_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"displayName": "build-01"}'

curl -s -X POST "https://api.kosem.ai/v1/projects/$KOSEM_PROJECT/environments" \
  -H "Authorization: Bearer $KOSEM_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"displayName\": \"devbox\", \"image\": \"node:24-bookworm\", \"runnerPool\": \"organizations/$KOSEM_ORG/runnerPools/$KOSEM_POOL\"}"
```

`CreateRunner` returns the runner resource and its one-time token:

```json
{
  "runner": {
    "name": "organizations/org_01m5r8w2k3e9vbt6g0d4x7qz1h/runnerPools/rnp_01m5rh2kq2e9vbt6g0d4x7qz1t/runners/rnr_01m5rh6mq2e9vbt6g0d4x7qz1u",
    "displayName": "build-01",
    "state": "PENDING",
    "paused": false
  },
  "registrationToken": "krt_…"
}
```

## Related [#related]

- [Self-hosted runners](/concepts/self-hosted-runners)
- [Manage self-hosted runners](/guides/environments/manage-self-hosted-runners)
- [Pull private images with a registry](/guides/environments/pull-private-images)
- [Limits and quotas](/reference/limits#environments)
