CircleCI self-hosted runners: Keep your code on your infrastructure and put idle compute to work
Director of Product Management
Some teams are happy to run every job on CircleCI’s managed infrastructure. Others have a good reason to keep the work closer to home.
If the latter sounds like you, self-hosted runners may be a good fit:
- Your security or compliance team prefers that source code and build artifacts stay inside your own network.
- You already have compute, such as Kubernetes clusters, reserved instances, or on-prem hardware, and you’d like CI to make use of it.
- Your jobs need to reach private systems, or run on an architecture or operating system that isn’t offered as a managed resource class.
With self-hosted runners, pipelines, the UI, and Insights stay in CircleCI, and the jobs themselves run on infrastructure you own. There are three ways to set that up. This post walks through when each one makes sense, what you need to get started, what performance to expect, and how to keep an eye on things over time.
Why self-hosted?
Security: your code never leaves your premises
With a self-hosted runner, jobs execute on machines you control, inside your network. The runner polls CircleCI for work, runs the job locally, and returns status, logs, and artifacts. A few properties matter to security teams:
- No inbound connectivity. The runner only makes outbound HTTPS connections to CircleCI. You don’t open firewall ports to receive work.
- Private network access. Jobs can reach internal registries, databases, artifact stores, and on-prem services that can’t be exposed to the internet.
- Identity you control. Give runners static IP addresses, attach cloud IAM roles (for example, on AWS), and monitor the operating system with the same tooling you use for the rest of your fleet.
- Your isolation model. Choose container-level isolation (container runner) or full VM-level isolation (machine runner and Machine Runner Orchestrator) to match your threat model.
- Scoped credentials. Runner resource class tokens can only claim tasks, and they can be rotated or revoked from the CLI.
If you’re running jobs in regulated or air-gapped-adjacent environments, you can also mirror the runner images to your own private registry and install from there.
Cost: use the compute you already own
Teams often have capacity that goes unused: reserved cloud instances, Kubernetes clusters sized for peak, build servers, and on-prem hardware. Self-hosted runners let you point CI at that capacity.
- Runner execution itself doesn’t consume credits. You need at least one credit on your account in case jobs use storage or networking.
- Container runner and Machine Runner Orchestrator run on Kubernetes, so CI jobs can share clusters you already operate and scale with demand.
- You can run architectures and machine shapes CircleCI doesn’t offer as a managed resource class (Arm, s390x, ppc64le, macOS, Windows Server).
- Machine runner is especially well suited to unique or proprietary hardware: lab equipment, embedded boards, IoT and edge devices, GPUs, or anything you can’t put in a cloud data center. If the thing you need to test against is a physical device, install machine runner on the host attached to it and your pipeline can run tests on the real hardware.
It’s not all or nothing. Self-hosted and CircleCI cloud resources work side by side, even within a single pipeline. Each job chooses where it runs through its resource_class, so you can send the jobs that touch sensitive code or need private network access to your own compute, and let everything else run on CircleCI’s managed infrastructure. Mix and match based on what each job needs:
workflows:
build-and-deploy:
jobs:
- lint-and-unit-test # runs on CircleCI cloud
- integration-tests: # runs on your own infrastructure
requires: [lint-and-unit-test]
- deploy: # runs on your own infrastructure
requires: [integration-tests]
jobs:
lint-and-unit-test:
docker:
- image: cimg/node:20.0
resource_class: medium
steps:
- checkout
- run: npm test
integration-tests:
docker:
- image: cimg/node:20.0
resource_class: my-namespace/my-container-runner
steps:
- checkout
- run: npm run test:integration
deploy:
machine: true
resource_class: my-namespace/my-machine-runner
steps:
- checkout
- run: ./deploy.sh
That way you only take on running the infrastructure where it earns its keep.
Which runner is right for you?
| Container runner | Machine runner | Machine Runner Orchestrator | |
|---|---|---|---|
| Where it runs | Kubernetes cluster | VM or bare metal (Linux, macOS, Windows, or Docker) | Kubernetes cluster with KubeVirt |
| Each job runs in | Ephemeral pod, your Docker image | The host where the runner is installed | A dedicated VM, created on demand |
| Isolation | Container-level | VM-level | VM-level, ephemeral |
| Scaling | Pods scale automatically; you scale the cluster | Manual or custom (for example, autoscaling groups) | Pods scale automatically; you scale the cluster |
| Best for | Docker-based jobs, Kubernetes-native teams | Full OS access, macOS/Windows, proprietary hardware, IoT and edge devices | Strong isolation with elastic VM capacity |
In short, choose container runner if your jobs use the Docker executor today, machine runner if you need a full OS, need to run on specialized hardware or devices, or don’t use Kubernetes, and Machine Runner Orchestrator if you want machine-runner isolation with Kubernetes-style autoscaling.
Requirements and setup
All three share the same first step: create a namespace and a resource class, which gives you a resource class token (shown once, so store it safely). You configure jobs to use the resource class with resource_class: <namespace>/<resource-class>. Each organization has a single namespace, shared with any orbs you publish.
circleci namespace create <name> --org-id <your-organization-id>
circleci runner resource-class create <namespace>/<resource-class> --description "My runner" --generate-token
Container runner
Requirements
- Kubernetes 1.25+ (any provider) and Helm 3.x
- A Kubernetes namespace without other workloads
- Linux nodes, amd64 or arm64
- Outbound HTTPS to CircleCI, and outbound port 22 if you use the checkout step over SSH
High-level setup
helm repo add container-agent https://packagecloud.io/circleci/container-agent/helm
helm repo update
kubectl create namespace circleci
# values.yaml: agent.resourceClasses.<namespace>/<resource-class>.token
helm install container-agent container-agent/container-agent -n circleci -f values.yaml
Then run a job with the Docker executor and your resource class:
jobs:
build:
docker:
- image: cimg/base:2021.11
resource_class: <namespace>/<resource-class>
steps:
- checkout
- run: echo "Hi I'm on Runners!"
Container runner claims tasks and schedules each one in an ephemeral pod. It works with CircleCI convenience images and your own custom images. It doesn’t scale your cluster for you, so pair it with your cluster autoscaler.
Go deeper: Container runner installation · Container runner reference
Machine runner
Requirements
- Root access on the target machine
- Linux (Ubuntu 18.04+, RHEL 8, SUSE, Debian; x86_64, ARM64, s390x, ppc64le), macOS 11.2+ (Intel or Apple silicon), or Windows Server (x86_64)
- Standard utilities on Linux: coreutils, curl, tar, gzip, GPG 2.1+
- Outbound HTTPS to
runner.circleci.com; no inbound connectivity required
High-level setup (Debian/Ubuntu)
curl -s https://packagecloud.io/install/repositories/circleci/runner/script.deb.sh?any=true | sudo bash
sudo apt-get install -y circleci-runner
# add your resource class token to /etc/circleci-runner/circleci-runner-config.yaml
sudo systemctl enable circleci-runner && sudo systemctl start circleci-runner
Jobs use machine: true plus your resource class. Use single-task mode for fully ephemeral hosts, or continuous mode for long-lived ones. If you don’t use Kubernetes but still want containerized jobs, you can run machine runner in Docker.
Go deeper: Linux · macOS · Windows · Docker · Scaling self-hosted runners
Machine Runner Orchestrator
Machine Runner Orchestrator (MRO) is a Kubernetes controller that scales CircleCI runner VMs using KubeVirt. It polls CircleCI for pending and running tasks and adjusts a VirtualMachinePool to match demand. Each job gets a full VM that is provisioned on demand and shut down afterward.
Requirements
- A Kubernetes cluster with KubeVirt installed (the chart does not install it; MRO has been tested with KubeVirt v1.8)
kubectland Helm 3+- A resource class token for each class you provision
High-level setup
The image and Helm chart are publicly available, with no registry credentials or invitation needed. Install the chart, point it at your resource class token, and set a VM size plus minReplicas (a pre-warmed pool) and maxReplicas (your capacity ceiling).
Go deeper: Machine Runner Orchestrator overview
Performance you can plan around
We publish benchmarks for container runner and MRO, including the settings we changed and the ones we left at defaults, so you can size your deployment with evidence rather than guesswork.
Container runner
Benchmarks ran on a deliberately modest reference cluster: GKE 1.29 with five E2-medium nodes and no autoscaling. Bigger or more powerful nodes will do better. We tested batches of 20 to 128 tasks launched at once, with 1 to 3 container agent replicas and 20 to 80 concurrent tasks per replica.
Two reference configurations come out of the data. Here is how each performed as the batch size grew (times in milliseconds):
High stability (the default): 1 replica, 20 concurrent tasks
| Tasks launched | Failure rate | Avg run time | Avg queue time | Max queue time |
|---|---|---|---|---|
| 20 | 0% | 2,092 | 23,581 | 30,639 |
| 40 | 0% | 1,786 | 35,307 | 60,009 |
| 80 | 0% | 1,755 | 66,260 | 126,222 |
| 128 | 0% | 1,809 | 107,782 | 207,405 |
High performance: 3 replicas, 80 concurrent tasks
| Tasks launched | Failure rate | Avg run time | Avg queue time | Max queue time |
|---|---|---|---|---|
| 20 | 0% | 1,939 | 18,014 | 23,248 |
| 40 | 0% | 2,386 | 24,865 | 32,445 |
| 80 | 1.25% | 3,951 | 45,000 | 60,557 |
| 128 | 0% | 3,855 | 76,667 | 103,048 |
Across all 36 combinations we tested, failure rates were at or near zero (the worst case was 1.25%), and average run time was about 2.5 seconds.
What to take from this:
- Queue time is the lever. The high performance setup cut average queue time by roughly 30% at 128 tasks (and cut max queue time about in half) compared with the default, because more replicas claim tasks faster when a large backlog lands at once.
- Stability costs little. The default configuration had no failures in any run. The high performance setup traded a small amount of run-time consistency for throughput on this small cluster.
- Your cluster sets the ceiling. More replicas and more concurrency put more strain on the Kubernetes control plane and kubelets. Give nodes headroom beyond what tasks request, and reliability improves as you add nodes and CPU.
Machine Runner Orchestrator
MRO benchmarks ran on AWS EKS with c8i.12xlarge nodes (48 vCPU / 96 GiB) and KubeVirt, using jobs that each do five minutes of work. Only minReplicas and maxReplicas varied.
- Small VMs (2 vCPU / 8 GiB,
maxReplicas34): at up to 6 jobs per minute, queue p90 stayed at or below 86 seconds. - Large VMs (8 vCPU / 32 GiB,
maxReplicas9): queue p90 was 82 seconds at 2 jobs per minute but rose to 1,574 seconds at 6 jobs per minute. The ceiling was the limit, not the orchestrator. - Bursts: 49 small-VM jobs arriving in 60 seconds had a queue p50 of 171 seconds during the burst and recovered to a queue p90 of 34 seconds in cooldown.
- Reliability: every job in every experiment completed with zero errors. When demand exceeds
maxReplicas, jobs wait; they aren’t dropped.
Sizing guidance from the tests: set maxReplicas for your expected peak (node memory divided by VM size, minus a buffer for system pods), make sure the sum across resource classes sharing a node group fits in that memory, split workloads across right-sized resource classes, and use headroom to keep pre-warmed VMs ready before a burst.
Machine runner
Because each machine runner is a host you provision, throughput is a function of your fleet. Scale it on queue depth using the runner API and the single-task / idle-timeout settings described in the scaling guide.
Full data: Container runner benchmarks · MRO benchmarks
How much can it handle before performance degrades?
None of the runners has a hard cutoff. Each one degrades gradually and predictably, which makes capacity planning simple.
- Container runner: We tested up to 128 tasks launched at once on the small reference cluster. On the default setup, run time stayed flat and there were no failures at any batch size. What grows is queue time, roughly in proportion to the backlog (average queue went from about 24 to 108 seconds as the batch grew from 20 to 128 tasks). The limit comes from Kubernetes control plane and kubelet strain, so more nodes and CPU push it out. We haven’t published data beyond 128 tasks at once.
- Machine Runner Orchestrator: Queues start to build when jobs arriving per minute multiplied by job length in minutes exceeds
maxReplicas. In our tests with 5-minute jobs, the large VM class (9 replicas) held a queue p90 of 82 seconds at 2 jobs per minute (about 10 concurrent jobs), but rose to 518 seconds at 4 jobs per minute and 1,574 seconds at 6. The small VM class (34 replicas) stayed at or below 86 seconds at 6 jobs per minute (about 30 concurrent jobs). RaisemaxReplicasto match your peak, and jobs wait rather than fail when you’re over. - Machine runner: Capacity is the number of hosts you provision. Scale it on queue depth using the runner API.
Monitoring your runners over time
Running your own fleet means you own its health. Today you can:
- Check fleet health from the CLI or API.
circleci runner fleet listandcircleci runner fleet get <namespace>/<resource-class>report active, idle, and disconnected agents, running and queued tasks, and when a task was last claimed. The same data is available from the Runner Fleets endpoints in API v3 (GET /api/v3/runner/fleets). These endpoints are experimental, so field names may change. - Drive autoscaling and queue-depth alerts from queued tasks, for example
circleci runner fleet get my-org/my-runner --json --jq '.queued_tasks'. To find resource classes with no connected agents, filtercircleci runner fleet list --jsononagent_countequal to 0. - See every connected agent with
circleci runner instance list, which shows whether each is online, idle, or offline, whether it is busy, and when it last claimed a task. The Runners page in the web app shows the runner inventory (circleci runner open). - Use the Self-hosted runner API to list resource classes, unclaimed tasks, and running tasks, which is enough to drive autoscaling and queue-depth alerts.
- Manage resource classes and tokens from the CLI (
circleci runner resource-class,circleci runner token). - Send pipeline and job data to your observability tools with the Datadog, New Relic, Sumo Logic, and OpenTelemetry integrations.
Coming soon.
- Resources: Windows and ARM support through end of year
- Security: Improved Token Management through end of year
Getting started
- Create a namespace and resource class, and save the token.
- Pick your runner: container runner for Kubernetes and Docker jobs, machine runner for full OS access, or Machine Runner Orchestrator for elastic, VM-isolated capacity.
- Run a test job with your new
resource_class. - Size for your workload using the benchmark recommendations, then add autoscaling and monitoring.
Further reading