CircleCI’s self-hosted runner lets a job target your infrastructure instead of CircleCI’s cloud compute. The scheduling, web UI, and pipeline editing stay in the cloud; the executor is yours. This is the right shape when jobs need to reach private VPC resources, when artifacts cannot leave your network for compliance reasons, or when GPU/ARM hardware costs less to own than to rent per-minute. This article covers the install, the resource class plumbing, and the agent fleet pattern.
How to verify
systemctl status circleci-runner
journalctl -u circleci.service -n 100
sudo -u circleci /opt/circleci/circleci-launch-agent --version
curl -fsS https://runner.circleci.com/health
circleci runner resource-class list --token $TOKEN
circleci runner token list --resource-class ns/rc --token $TOKEN
A healthy agent shows Started polling for tasks in its log every minute. If you see “no tasks” forever and jobs in the UI sit in pending, the resource class on the job doesn’t match the resource class the runner is registered for — that mapping is the most common misconfiguration.
What’s happening
CircleCI separates two things: the launch agent (a long-lived daemon that polls CircleCI’s runner.circleci.com for work), and the task agent (a short-lived process spawned per job that does the actual checkout, command execution, and artifact upload). The launch agent stays connected; the task agent comes and goes.
Resource classes are how CircleCI maps jobs to runner pools. A self-hosted resource class is named <namespace>/<rc-name> (e.g. acme/build-arm64). The job’s .circleci/config.yml says resource_class: acme/build-arm64, the runner is registered as serving acme/build-arm64, and CircleCI routes the job to one of the launch agents in that pool. Add more agents to scale the pool; remove agents and jobs queue.
The two install modes:
- Machine runner — runs on a host (VM or bare metal), task agents execute jobs directly in that host’s shell or in containers it spawns. Faster, but the same agent runs every tenant’s job; isolation is whatever you build.
- Container agent — runs in Kubernetes, each task is a fresh pod. Slower spin-up, true isolation per job. Use this for shared multi-tenant CI.
The procedure
-
Create a namespace and resource class in the CircleCI UI (Organization → Self-Hosted Runners). Save the runner token.
-
Install the launch agent on Ubuntu:
curl -fsSL https://packagecloud.io/circleci/runner/gpgkey \ | sudo gpg --dearmor -o /usr/share/keyrings/circleci-runner.gpg echo "deb [signed-by=/usr/share/keyrings/circleci-runner.gpg] \ https://packagecloud.io/circleci/runner/any any main" \ | sudo tee /etc/apt/sources.list.d/circleci-runner.list sudo apt-get update && sudo apt-get install -y circleci-runner -
Configure the runner in
/etc/circleci-runner/circleci-runner-config.yaml:api: auth_token: "<RUNNER_TOKEN>" runner: name: "build-arm64-01" mode: single-task working_directory: /tmp/%s cleanup_working_directory: true command_prefix: ["sudo", "-niHu", "circleci", "--"]mode: single-taskmeans one job at a time per agent — pair withspawnsemantics by running multiple agent instances.command_prefixruns every task as the dedicatedcircleciuser. -
Start.
systemctl enable --now circleci-runner. The agent registers, polls, and appears in the CircleCI UI within seconds. -
Reference the resource class in
.circleci/config.yml:version: 2.1 jobs: build: machine: true resource_class: acme/build-arm64 steps: - checkout - run: make build workflows: ci: jobs: - build -
Container agent (Kubernetes variant). Install via Helm:
helm repo add container-agent https://packagecloud.io/circleci/container-agent/helm helm install -n circleci --create-namespace container-agent \ container-agent/container-agent \ --set agent.resourceClasses[0].resource_class="acme/build-k8s" \ --set agent.resourceClasses[0].token="<TOKEN>"Each job runs in a fresh pod with the configured resource limits — true isolation per job, with the Kubernetes scheduler doing the bin-packing.
-
Autoscaling. For machine runners on AWS, CircleCI publishes a Terraform module that runs an ASG sized by queue depth. For Kubernetes container agents, scale the underlying node pool with Karpenter or Cluster Autoscaler — the agent itself doesn’t change.
-
Secrets. CircleCI projects have context-scoped environment variables; these are injected into the task agent’s environment. For runner-side secrets (registry credentials, VPC tokens), use the host’s vault and inject in a
pre-runscript that lives in/var/opt/circleci/scripts/and is run bycommand_prefix.
Common pitfalls
- Resource class typo. Job in
.circleci/config.ymlsaysacme/build-x64, runner is registered asacme/build-amd64. Job queues forever with no error. - Shared machine runner, no
circleciuser. Withoutcommand_prefix, tasks run as root or asubuntu. A malicious pipeline owns the host. - Container agent without resource limits. A task with no
resourcesrequest consumes whatever the node has free; one runaway job evicts the others. cleanup_working_directory: false. Disk fills within days. Only disable for debugging.- Forgot to restart agents after token rotation. Old agents fail to register but stay in the UI as “online”; new tasks route to them and time out.
We run CircleCI self-hosted runners for clients who want the cloud control plane but need jobs touching private infrastructure — deploying to internal Kubernetes clusters, reading from internal artifact stores, running against air-gapped test environments. The agent hosts, container-agent Helm release, autoscaling rules, and credential injection are managed by our team; the .circleci/config.yml files belong to the dev teams. That delivery shape is part of /en/services/managed-operations/.