Self-hosted CI runners can reduce queue time, support private network access, and handle specialized workloads, but they also turn build infrastructure into a security and operations responsibility. This guide provides a repeatable way to choose between hosted, ephemeral, static, and Kubernetes-based runners; harden the selected design; and estimate capacity and operating cost without relying on fixed vendor prices.
Overview
A CI runner executes the jobs defined by your pipeline. It checks out code, installs dependencies, runs tests, builds artifacts, performs security checks, and may deploy applications. The runner model determines how much control your team has over the environment and how much maintenance it must accept.
Hosted runners are operated by the CI provider and are often the simplest starting point. Self-hosted runners are operated by your team and may run on virtual machines, physical hosts, containers, or Kubernetes. The important distinction is not simply where a runner runs, but whether one job can influence another job and what credentials or network paths are available during execution.
| Runner model | Cost pattern | Isolation | Startup time | Maintenance | Network access | Best fit |
|---|---|---|---|---|---|---|
| Hosted runner | Usage-based or included allowance | Provider-managed isolation; verify platform details | Usually predictable | Low infrastructure maintenance | Limited to approved provider paths and configuration | General builds, open connectivity, small teams |
| Ephemeral self-hosted runner | Compute and control-plane usage per job | Strongest practical separation when destroyed after one job | Depends on provisioning | Moderate automation maintenance | Can be placed in private networks | Untrusted code, sensitive builds, bursty workloads |
| Static self-hosted runner | Persistent host cost, regardless of utilization | Lower unless workspaces and execution are carefully isolated | Fast after the host is ready | High patching and cleanup responsibility | Flexible, including private network access | Stable internal workloads and specialized software |
| Kubernetes-based runner | Cluster capacity plus runner and orchestration overhead | Pod-level isolation, subject to cluster configuration | Includes pod scheduling and image pull time | Moderate to high platform maintenance | Flexible through cluster networking controls | Teams already operating Kubernetes and variable workloads |
There is no universally safest or cheapest option. Hosted runners reduce infrastructure ownership. Ephemeral self-hosted runners are often a strong default for sensitive or untrusted workloads because their workspaces and local state can be discarded after each job. Static runners can be efficient for trusted, predictable jobs, but persistent machines require disciplined patching, cleanup, and access control. Kubernetes runners can scale with demand, but they add cluster scheduling, image, and identity considerations.
How to estimate
Start with workload measurements rather than a runner count chosen by habit. Collect at least one representative period of pipeline data and record:
- Number of jobs started per hour and per day.
- Average and high-percentile job duration, excluding queue time.
- Peak simultaneous jobs, including scheduled and manually retried work.
- CPU, memory, disk, network, and accelerator requirements for each job class.
- Required private network destinations, such as package registries, test services, or deployment endpoints.
- Whether jobs can execute untrusted pull-request code or access production credentials.
A useful first estimate for concurrent capacity is:
Required runners = peak concurrent jobs × safety factor
Use a safety factor to absorb short bursts, retries, maintenance, and uneven job durations. Treat it as an explicit assumption rather than a hidden buffer. If peak concurrency is 12 and the team chooses a 25% operational buffer, the starting target is 15 concurrent execution slots. Capacity should be measured in slots only when jobs have similar resource demands. Otherwise, create separate pools, such as small Linux builds, memory-heavy integration tests, Windows jobs, or deployment runners.
To estimate compute consumption, use:
Runner-hours = completed job count × average execution minutes ÷ 60
Then add expected overhead for image pulls, provisioning, idle time, failed jobs, and maintenance. For an ephemeral model, estimate provisioning time and teardown activity separately. For a static model, include the full period during which hosts are allocated, not only the minutes spent running jobs.
For a broader operating-cost estimate, use this worksheet:
- Compute: runner or cluster capacity multiplied by allocated runtime.
- Storage: operating disks, cached dependencies, container layers, logs, and retained artifacts.
- Network: transfers between runners, registries, artifact stores, and private services.
- Platform operations: patching, image maintenance, monitoring, incident response, and access reviews.
- Security controls: isolation technology, scanning, audit retention, and identity integration.
Keep provider pricing, internal labor rates, retention periods, and currency in separate inputs. This makes the worksheet easier to update when pricing inputs change without rewriting the decision model.
Inputs and assumptions
Runner-hardening checklist
- Use disposable workspaces: create a clean workspace for each job and remove it afterward. Never assume that deleting the repository directory removes all secrets or caches.
- Limit identity permissions: issue separate identities for build, test, and deployment tasks. Prefer short-lived credentials and environment-specific permissions.
- Separate trust zones: do not place untrusted pull-request jobs on a runner that can reach production systems or contains long-lived credentials.
- Isolate execution: use an appropriate container, virtual machine, or Kubernetes boundary. Remember that a container alone does not automatically prevent host, socket, filesystem, or credential exposure.
- Control secret exposure: avoid printing secrets, passing them through command-line arguments, or making them available to jobs that do not need them. For a deeper comparison of options, see the Secrets Management for CI/CD guide.
- Restrict network egress: allow only required registries, repositories, package services, and deployment endpoints. Log denied and permitted connections where practical.
- Patch the base image: define an owner, rebuild cadence, vulnerability response process, and rollback path for runner images.
- Log useful events: record runner registration, job assignment, image or host version, permission changes, failures, and cleanup results without collecting sensitive job output unnecessarily.
- Clean up reliably: remove temporary files, credentials, containers, volumes, caches, and registration tokens even when a job fails or is cancelled.
- Protect administration: restrict who can register, label, pause, modify, or access runners. Treat runner registration tokens and configuration files as sensitive.
Repository onboarding workflow
- Classify the repository by trust level, data sensitivity, operating system, architecture, and network requirements.
- Select a runner pool with labels that describe capabilities rather than business secrets. Avoid labels that grant access by implication.
- Define the minimum permissions for source checkout, artifact storage, package access, and deployment.
- Run a small validation pipeline that checks tool versions, network reachability, workspace cleanup, and log redaction.
- Test cancellation, timeout, retry, and failure paths. Confirm that cleanup occurs in each case.
- Enable monitoring for queue time, job duration, runner availability, failure rate, disk usage, and image age.
- Document ownership, escalation, rotation procedures, and removal steps before enabling production deployment jobs.
Reusable pipeline definitions can make this process consistent across repositories. The GitHub Actions reusable workflows guide provides a related pattern for centralizing CI/CD behavior.
Worked examples
Example 1: Bursty application builds
Assume a team records 10 peak concurrent jobs, with a 30% buffer for retries and short bursts. The initial capacity target is 13 execution slots. If most jobs are interchangeable, those slots can be provided by an ephemeral pool. If integration tests require private services, place that pool in the appropriate network segment and restrict its egress rather than giving every runner broad access.
The team should compare the cost of keeping 13 static hosts available with the cost of provisioning ephemeral capacity only when the queue grows. The calculation should include startup delay: a cheaper ephemeral design may be unsuitable if image pulls and provisioning regularly exceed the team’s acceptable queue time.
Example 2: Mixed workload repository fleet
Suppose a fleet contains fast lint jobs, memory-heavy integration tests, and deployment jobs requiring tightly controlled credentials. A single runner pool obscures the real capacity requirement. Create three pools and measure each independently:
- Small, inexpensive runners for linting and unit tests.
- Larger ephemeral runners for integration tests, with strict cleanup and network controls.
- A restricted deployment pool with limited repository access, approval requirements, and no general-purpose build execution.
This design may use more configuration, but it prevents low-cost jobs from competing with expensive tests and reduces the blast radius of a compromised build.
Example 3: Kubernetes-based execution
A team already operating Kubernetes may schedule one runner pod per job. Its worksheet should include pod startup time, image-pull frequency, node capacity, namespace quotas, persistent-volume behavior, service-account permissions, and cluster autoscaling delay. Runner pods should not inherit broad permissions simply because they run in the cluster. Review the deployment model alongside your wider Kubernetes resource requests and limits.
When to recalculate
Revisit the model whenever the inputs change, not only when a pipeline fails. Recalculate after adding repositories, changing test suites, introducing a new operating system or architecture, moving workloads into Kubernetes, changing artifact retention, or enabling deployment from CI. Also review the estimate after a sustained increase in queue time, repeated capacity-related failures, unexpected network or storage usage, or a security audit finding.
Pricing and platform behavior can change independently of workload volume. Keep a dated record of provider rates, compute types, image sizes, retention settings, and internal operations assumptions. When comparing hosted runners with self-hosted CI runners, update both direct infrastructure costs and the operational effort required to patch, monitor, secure, and troubleshoot them.
As a practical next step, create one inventory row per runner pool with these fields: workload class, trust level, peak concurrency, average duration, resource profile, network destinations, credential scope, isolation method, owner, and last review date. Start with the lowest-risk repository, validate cleanup and permissions, then expand gradually. If queue time improves but security controls become harder to explain, stop and redesign the pool boundaries. A runner is ready for broader adoption only when its capacity assumptions, isolation model, and operating ownership are all clear.