Skip to content

Run a runner in the cluster

A step-by-step guide for an administrator who sets up an agent-runner for a person without a machine of their own: the runner runs as a pod on hetzner-mgmt, uses the person's own Codex (ChatGPT) subscription, and takes tasks only from the person's organization. The reasoning — why containers, why updates come from the image, how the login survives restarts and which risk was accepted — is in ADR-0006, Container runners. The manifests and their reference are in components/agent-runner/ (see its README.md); the steps below match it.

The Helm chart

Runners on our clusters run agent-runner's Helm chart (oci://harbor.prod.skatzi.com/skatzi/charts/agent-runner) as a Flux HelmRelease; components/agent-runner/ adds the OpenBao secrets, the Codex login sync and the Cilium policies. To run an agent runner in a cluster outside our platform, use the chart on its own with agent-runner's Kubernetes guide instead.

The examples use the first such runner, emilia-container-agent for emilia in organization Emmalia (id 8). For a new person, replace:

Placeholder in this guide Example Meaning
<runner> emilia-container-agent Runner name: the person and the provider
<person> emilia The person's Keycloak username, the runner's owner
<org> Emmalia (id 8) The organization the runner works for
<cluster> hetzner-mgmt The cluster the pod runs on

What gets created

flowchart LR
    subgraph People
        P[Person with a phone]
        A[Administrator]
    end
    subgraph Accounts
        KC[Keycloak user runner-name]
        GT[Gitea account and token]
        TB[Taskbase runner, owner and scope]
    end
    subgraph OpenBao
        S1[Password and Gitea token]
        S2[Codex login]
        AR[AppRole for the login sync]
    end
    subgraph Pod
        R[runner]
        SY[codex-auth-sync]
        RS[resizer]
    end
    API[Kubernetes API]
    A --> KC
    A --> GT
    A --> TB
    A --> S1
    A --> AR
    S1 --> R
    S2 --> R
    SY --> S2
    RS -- resize own pod --> API
    P -- device login --> R

The pod has no persistent volume. Workspaces live in an emptyDir and are lost on restart, which is fine because every run clones fresh. Only the Codex login has to survive, so it is kept in OpenBao: an init container seeds it, and the codex-auth-sync sidecar writes it back whenever Codex rotates it.

Before you start

  • kubectl access to <cluster> (Kubernetes access) and an OpenBao admin token (bao CLI, BAO_ADDR=https://openbao.prod.skatzi.com).
  • Admin access to Keycloak realm skatzi, to Gitea, and to the Taskbase control room (or reach to <org>, which is enough to create an organization runner).
  • The person has a ChatGPT subscription that includes Codex, a Claude subscription that can run claude setup-token, or both, and a phone or browser to approve the login. You never need their password.
  • The agent-runner chart and image are in Harbor (oci://harbor.prod.skatzi.com/skatzi/charts/agent-runner:<version> and harbor.prod.skatzi.com/skatzi/agent-runner:v<version>). agent-runner's release workflow pushes both for every v* tag.

1. Create the Keycloak user

In realm skatzi, create runner-<runner> with a password, no OTP and no required actions. It needs no roles and no organization grants: the runner's scope in Taskbase decides what it may claim. Keep the password for step 4.

2. Create the Gitea account and token

Create the account runner-<runner> and add it to <org>'s Developers team. As that account, create a token with write:repository, write:issue, read:user and read:organization. Keep the token for step 4.

3. Create the runner in Taskbase

In the control room, create the runner <runner>: scope organization, organization <org>, owner <person>, Keycloak user runner-<runner>. As its owner, the person can then pause, drain, resume and cap it themselves (see Runner owners). The Runners page will show Updated by image for it instead of target-version controls.

4. Write the runner secrets to OpenBao

The external-secrets AppRole must be able to read clusters/data/<cluster>/agent-runners/*.

read -rs PASSWORD && read -rs GITEA_TOKEN
bao kv put -mount=clusters hetzner-mgmt/agent-runners/emilia-container-agent \
  password="$PASSWORD" gitea_token="$GITEA_TOKEN"
unset PASSWORD GITEA_TOKEN

The ExternalSecret <runner>-credentials syncs them into files the runner reads as password_file and gitea_token_file.

5. Create the AppRole for the login sync

With an admin token, create a policy that reaches only this runner's Codex login, an AppRole with it, and store the AppRole's credentials in OpenBao:

bao policy write agent-runner-emilia-container-agent-codex-auth - <<'HCL'
# Only the Codex login of runner emilia-container-agent, nothing else.
path "clusters/data/hetzner-mgmt/agent-runners/emilia-container-agent-codex-auth" {
  capabilities = ["create", "update", "read"]
}
HCL

bao write auth/approle/role/agent-runner-emilia-container-agent-codex-auth \
  token_policies=agent-runner-emilia-container-agent-codex-auth \
  token_no_default_policy=true \
  token_ttl=5m token_max_ttl=5m \
  secret_id_ttl=0 secret_id_num_uses=0

ROLE_ID=$(bao read -field=role_id \
  auth/approle/role/agent-runner-emilia-container-agent-codex-auth/role-id)
SECRET_ID=$(bao write -f -field=secret_id \
  auth/approle/role/agent-runner-emilia-container-agent-codex-auth/secret-id)
bao kv put -mount=clusters hetzner-mgmt/agent-runners/emilia-container-agent-codex-auth-approle \
  role-id="$ROLE_ID" secret-id="$SECRET_ID"
unset ROLE_ID SECRET_ID

The ExternalSecret <runner>-codex-auth-approle syncs it into a Secret mounted only into the codex-auth-sync sidecar, never into the runner. The pod does not start until that Secret exists. Do not write <runner>-codex-auth yourself: the sidecar creates it at the first login.

6. Check the network policy

Do this for the first runner on a cluster and after any change to the agent-runners policies:

components/agent-runner/verify-network-policy.sh

It starts a throwaway pod with the runner's labels. It must report the kube-apiserver (allowed only to the runners that resize their pod, see Idle and active size), OpenBao's cluster port, Keycloak's management port, the Postgres services of Gitea and Taskbase, kube-dns metrics and the metadata endpoint as blocked, and Taskbase, the MCP server, Gitea, Keycloak, OpenBao's public /v1/sys/health, api.openai.com, api.anthropic.com and registry.npmjs.org as open. A 403 Access denied from the gateway counts as blocked: it means the policy lacks the rule for that hostname's backend (see the component README, "Network policy"). Its last check gives the Gitea pod a new identity with a label and expects Gitea to keep answering; a failure there means Cilium did not refresh the gateway's copy of the runner's policy (see the ops runbook). Do not go on if it fails; the pod would run untrusted code next to the platform's services.

7. Add the runner and start the pod

The chart always runs one pod, so this comes after the secrets. Skip it for emilia-container-agent, which exists already. For a new runner, open a pull request in Skatzi/platform:

  1. Copy cluster/<cluster>/agent-runners/emilia-container-agent/ to cluster/<cluster>/agent-runners/<runner>/. It holds only the runner's own chart values, in helm-release.yaml; everything runners share (the Codex login containers, the OpenBao secrets, the Cilium policies instead of the chart's NetworkPolicy) is in components/agent-runner/runner/.
  2. In its helm-release.yaml, keep the codex models the person's subscription offers, and drop the role=reviewer label unless the runner should take reviews. Settings the chart has no value for go in extraConfig (see agent-runner's agent-runner.example.yaml). Change resources only if this runner needs more than 2 CPU, 4 Gi memory and 20 Gi ephemeral storage. The runner's name, Keycloak user and Gitea user default to <runner>; if the users from steps 1 and 2 are named differently, set runner.username and runner.giteaUsername.
  3. In cluster/<cluster>/agent-runners/kustomization.yaml, copy the Flux Kustomization agent-runner-emilia-container-agent to agent-runner-<runner>, with its path, runner_name and health-check name changed. Its agent_runner_version is the agent-runner release to run, e.g. "0.5.18": the chart of that version, which runs the image of that version.

Merge it. Flux pulls the chart from Harbor, installs the release and starts the pod:

kubectl --context admin@mgmt-cluster get helmrelease,pod -n agent-runners -l app.kubernetes.io/instance=<runner>
kubectl --context admin@mgmt-cluster logs -n agent-runners deploy/<runner> -c runner | grep registered

Until the person has logged in, the runner registers and heartbeats but its Codex adapter has no login.

8. Log the person in to Codex

Arrange a moment with the person; the code is valid for 15 minutes. Then run:

kubectl --context admin@mgmt-cluster exec -it -n agent-runners deploy/emilia-container-agent -c runner -- \
  codex login --device-auth -c 'cli_auth_credentials_store="file"'

It prints https://auth.openai.com/codex/device and a one-time code. Send both to the person: they open the link on their phone, sign in to ChatGPT and enter the code. If ChatGPT refuses the code, they first enable device code login for Codex in ChatGPT's security settings. The cli_auth_credentials_store="file" option makes sure the login goes to ~/.codex/auth.json, which the sidecar watches, and not to a keyring.

Check it:

kubectl --context admin@mgmt-cluster exec -n agent-runners deploy/emilia-container-agent -c runner -- codex login status
kubectl --context admin@mgmt-cluster logs -n agent-runners deploy/emilia-container-agent -c codex-auth-sync

Within a minute the sidecar logs auth.json changed, stored in OpenBao as version 1.

9. Check that the login survives a restart

kubectl --context admin@mgmt-cluster delete pod -n agent-runners -l app.kubernetes.io/instance=emilia-container-agent
kubectl --context admin@mgmt-cluster logs -n agent-runners deploy/emilia-container-agent -c seed-codex-auth
#   seed-codex-auth: seeded /data/home/.codex/auth.json from OpenBao
kubectl --context admin@mgmt-cluster exec -n agent-runners deploy/emilia-container-agent -c runner -- codex login status
#   Logged in using ChatGPT

The runner is now online on the Runners page and takes <org>'s agent tasks. Tell the person they own it.

Day-to-day

  • Update the runner: change agent_runner_version in its Flux Kustomization in cluster/<cluster>/agent-runners/kustomization.yaml in a pull request; the chart of that version runs the image of that version. Flux upgrades the release; the old pod first finishes or releases its runs (up to 25 minutes) before the new one starts. Rolling back is the same with an older version (0.5.18 is the oldest chart these values work with). Taskbase never sets a target version for it. Renovate opens that pull request when agent-runner tags a release, through the # renovate: comment above agent_runner_version; give a new runner's Kustomization the same comment (Renovate coverage).
  • Change its config: edit the overlay's helm-release.yaml in a pull request. The chart regenerates agent-runner.yaml, and the changed config restarts the pod on the upgrade.
  • Stop it for a while: set its slots to 0 on the Runners page; the chart has no replica count to scale down.
  • Logs: kubectl --context admin@mgmt-cluster logs -n agent-runners deploy/<runner> -c runner.
  • The runner gets 403 Access denied for a platform host (its Keycloak login fails and the pod restart-loops, or clones fail): ProbeFailed with component="agent-runners" fires for the same host. Follow the ops runbook.
  • Codex asks for a login again: the pod probably restarted within about two minutes of a token refresh and seeded the previous login. Repeat step 8.
  • Remove a runner: delete its overlay and Flux Kustomization in a pull request, delete the runner in Taskbase, and delete its OpenBao paths, its policy and its AppRole.

A secret for one organization's jobs

agent-runner's job_env (v0.5.29+, docs/secrets.md) adds environment variables to the agent of a task run, chosen by the task's organization. Chat turns and other organizations' runs do not get them, and the runner replaces every value with [REDACTED] in its run logs and in the summaries it reports. The example is HELLOWEEKLY_API_TOKEN, Hello Weekly's recipe API token, for Emmalia (organization 8) on emilia-container-agent (task #1906).

This is not isolation. A job runs in the runner's container as its user, so a job of any organization the runner serves can read /secrets/*, the key included. Give a runner an organization's secret only when its runner scope in Taskbase is that organization alone.

  1. Store the secret in OpenBao at the runner's path, with patch so the other keys stay:
read -rs TOKEN
bao kv patch -mount=clusters <cluster>/agent-runners/<runner> \
  helloweekly_api_token="$TOKEN"
unset TOKEN
  1. Add the key and the variable in the overlay, in a pull request, only after step 1: both the ExternalSecret and the runner fail while the key is missing. In kustomization.yaml:
patches:
  - path: helm-release.yaml
  - target:
      kind: ExternalSecret
      name: .*-credentials   # a regex; ${runner_name} would not match
    patch: |-
      - op: add
        path: /spec/data/-
        value:
          secretKey: helloweekly_api_token
          remoteRef:
            key: ${cluster_name}/agent-runners/${runner_name}
            property: helloweekly_api_token

and in helm-release.yaml, under extraConfig (the organization id is quoted, the value names the key):

job_env:
  "8":
    HELLOWEEKLY_API_TOKEN: secret:helloweekly_api_token

The changed config restarts the pod. The runner reads the secret when it starts and stops with an error naming the key if it is missing or empty. After changing only the value in OpenBao, wait for the ExternalSecret's refresh (1 hour, or kubectl --context admin@mgmt-cluster annotate externalsecret -n agent-runners <runner>-credentials force-sync=$(date +%s) --overwrite) and restart the pod.

  1. Check that the key is synced, without printing it:
kubectl --context admin@mgmt-cluster get externalsecret -n agent-runners <runner>-credentials
kubectl --context admin@mgmt-cluster get secret -n agent-runners <runner>-credentials \
  -o jsonpath='{.data}' | jq 'keys'

Hello Weekly's token is only on emilia-container-agent. mac-mini (native) serves Emmalia too, but also organizations 2, 3, 5, 9 and 10, whose jobs could read its secrets.json, so it does not get the token. Instead, emilia-container-agent carries the label helloweekly-api, and the recipe-editor's tasks require it (task #1995), so no other runner claims them. A native runner whose scope is one organization would get it the same way: agent-runner secrets set helloweekly_api_token (hidden prompt) and the same job_env entry in its agent-runner.yaml, then a restart.

Idle and active size

A runner works a few hours a day, but its resources requests (500m CPU, 1 Gi memory) would reserve node capacity around the clock. With the chart's resize (chart 0.5.25 and later) it reserves an idle size between runs and grows to resources in place while it has a run or chat turn. The pod is not restarted, so the Codex login and chat turns are untouched. The design is in agent-runner's Kubernetes guide, "Reserving resources only while working".

CPU request Memory request Limits, ephemeral storage
Idle (resize.idle) 50m 512 Mi unchanged
Active (resources) 500m 1 Gi (emilia: 1536 Mi) 2 CPU, 4 Gi; 15/20 Gi storage
  • Idle size. Set above a runner's measured idle use, with headroom. The 2026-10 measurement over 7 days found idle CPU under 12m (p95) and idle memory under 300 Mi (p95) with a peak of 456 Mi. resize.idle has no limits, so a runner keeps its full limits while idle and a run never meets a low limit while a grow is deferred.
  • The resizer sidecar reads the runner's /data/state.json every 5 seconds. It grows the runner as soon as it has a run or chat turn, and shrinks it 2 minutes after the last one ends. It is the only container with a Kubernetes token: the ServiceAccount <runner>-resizer, projected into the sidecar only, may get pods and patch pods/resize in agent-runners.
  • The scheduler sees the idle size. The pod template carries the idle requests, so a new pod is placed by them, and a larger active size does not move it to a node with room. To keep two growing runners off one node, both agents' overlays require, by pod anti-affinity, a worker without another agent runner, so a replacement waits Pending instead of sharing a worker (why). A grow that does not fit is reported as PodResizePending with one of two reasons. Deferred: the node has no room now; the kubelet retries and applies the grow once room frees up. Infeasible: the node can never fit it (the size is above its allocatable), so it is never applied, and only a smaller resources or a larger node clears it. In both cases the run goes on at the size it has, with the full limits.
  • A run that outgrows its node is the one killed. A run can grow to its 4Gi limit whatever its request, and on an 8 GB worker that can leave the node short of memory. On the hetzner-mgmt workers the kubelet's soft eviction acts first: below 2 GiB available it evicts a pod above its request (lowest priority first, then the furthest over), often a runner in a run, and the run is lost (worker memory eviction; incident 2026-11-12, #2884). If memory falls faster than that, Talos's OOM controller kills the largest pod on the node, limited or not, which is then the runner: the run is lost and the pod restarts. Before the hetzner-mgmt OOMConfig, it never chose a runner and killed platform pods instead (hetzner-mgmt: Talos's OOM controller).
  • Each sidecar resizes only its own pod. The ValidatingAdmissionPolicy agent-runner-resize-own-pod (components/agent-runner/namespace/) refuses a resize by a ServiceAccount of agent-runners unless the pod is the one its token is bound to.
  • API egress. The sidecar calls the API server on TCP 6443. The cluster policy agent-runner-kube-apiserver allows that for the runners listed in it. Add a runner to that list when you turn on resize for it. The baseline's deny of nodes and the API server leaves out TCP 6443 so that allow can work. The policy applies to the whole pod, so the runner container reaches the API server too, but it has no token.

To turn it on for a runner, add it to agent-runner-kube-apiserver and set resize in its overlay's helm-release.yaml in the same pull request:

resize:
  enabled: true
  idle:
    requests: {cpu: 50m, memory: 512Mi}

Check it:

pod=$(kubectl --context admin@mgmt-cluster -n agent-runners get pod -l app.kubernetes.io/instance=<runner> -o name)
# The idle requests between runs, the active ones during a run.
kubectl --context admin@mgmt-cluster -n agent-runners get $pod -o jsonpath='{.status.containerStatuses[?(@.name=="runner")].resources}'
# 0: a resize never restarts the runner.
kubectl --context admin@mgmt-cluster -n agent-runners get $pod -o jsonpath='{.status.containerStatuses[?(@.name=="runner")].restartCount}'
# "resize requested" and "resize applied" for every grow and shrink.
kubectl --context admin@mgmt-cluster -n agent-runners logs $pod -c resizer
# The requests the node has reserved.
kubectl --context admin@mgmt-cluster describe node <node> | sed -n '/Non-terminated Pods/,/Events/p'

The admission policy is checked with a server-side dry run that impersonates one runner's sidecar on another runner's pod (refused) and on its own (allowed); the commands are in agent-runner's Kubernetes guide, "Each sidecar resizes only its own pod".

Claude instead of (or besides) Codex

Claude Code authenticates with a long-lived token from claude setup-token, not a login that rotates on its own like Codex's auth.json, so there is no seed container, no sidecar and no AppRole: the token goes into OpenBao and the ExternalSecret <runner>-credentials syncs it as /secrets/claude_token (component README, "Claude login"). A runner can run Claude instead of Codex, or add it besides Codex as a second adapter. Steps 1 (Keycloak user) and 2 (Gitea account) are not Codex-specific: every runner still needs a Keycloak user and a Gitea account regardless of which adapter it runs. Step 5 (Codex AppRole) is also still required as things stand, because the codex-auth-approle volume in components/agent-runner/runner/helm-release.yaml is not optional and the pod does not start without that Secret, Claude-only or not. Only steps 8 and 9 (the device login and the restart check) are Codex-only; skip those two for a Claude-only runner.

  1. Generate the token. The image already has the Claude Code CLI:
kubectl --context admin@mgmt-cluster exec -it -n agent-runners deploy/<runner> -c runner -- claude setup-token

It prints a link for the person to approve on their phone or browser, then the token itself. Keep it; claude setup-token does not store it anywhere the runner can read.

  1. Store it in OpenBao, at the same path as the password and Gitea token, with patch so the existing keys are untouched:
read -rs CLAUDE_TOKEN
bao kv patch -mount=clusters <cluster>/agent-runners/<runner> \
  claude_token="$CLAUDE_TOKEN"
unset CLAUDE_TOKEN
  1. Turn Claude on in the overlay, in a pull request, only after step 2: the ExternalSecret fails to sync while the key is missing in OpenBao. In the overlay's kustomization.yaml, add the key to the credentials:
patches:
  - path: helm-release.yaml
  - patch: |-
      - op: add
        path: /spec/data/-
        value:
          secretKey: claude_token
          remoteRef:
            key: ${cluster_name}/agent-runners/${runner_name}
            property: claude_token
    target:
      kind: ExternalSecret
      name: .*-credentials   # a regex; ${runner_name} would not match

and in its helm-release.yaml:

claude:
  enabled: true
codex:
  enabled: false   # leave it on to offer both

The chart adds the claude adapter (Sonnet at small, Opus at medium and large, like the Mac mini runner; claude.models changes that), reads the token with claude_oauth_token_file, and gives Claude runs the Taskbase and read-only Gitea MCP servers. The changed config restarts the pod when Flux upgrades the release.

The network policy already allows api.anthropic.com — step 6's check covers it alongside api.openai.com, both on the baseline's world 443 rule, so no cluster-level change is needed for Claude.