Lesson 7 of 9 · 27m
Self-Hosted Runners: Architecture, Isolation, and Operations
When self-hosted runners are worth it, how to isolate them safely, and the operational practices that keep them from becoming unmanaged snowflakes.
Self-hosted runners are not 'free GitHub Actions.' They are a fleet of execution machines attached to your source control security model. They make sense for special hardware, private networks, cost control at scale, or toolchain constraints. They are a liability when they are long-lived pets running untrusted pull requests with production network access.
Choose the trust model first
A runner registered at repository scope serves that repository. Organization runners can serve many repositories, controlled by runner groups. Larger scope means better utilization and larger blast radius.
Repository A ─┐
Repository B ─┼─ runner group: linux-ci ── auto-scaled ephemeral pool
Repository C ─┘
deploy runner group ── protected repos only ── private network accessNever mix untrusted CI and privileged deployment workloads on the same runner group just because both need Linux. The network and identity context is the difference that matters.
Ephemeral runners are the baseline
A persistent runner accumulates state: leaked credentials, poisoned caches, leftover processes, modified toolchains, malware persistence. Ephemeral runners exist for one job and are destroyed afterward.
# actions-runner control shape, usually driven by your autoscaler
./config.sh --url https://github.com/myorg \
--token "$RUNNER_REGISTRATION_TOKEN" \
--name "ci-$(hostname)-$RANDOM" \
--runnergroup linux-ci \
--labels linux,x64,ephemeral \
--ephemeral \
--unattended
./run.sh --onceGitHub-hosted runners already behave this way. If you go self-hosted, reproduce that property. A self-hosted runner without isolation is often worse than paying GitHub.
Use containers or VMs as the isolation boundary
For Linux CI, Kubernetes-based Actions Runner Controller or VM autoscaling are common patterns. The details differ, but the rules do not:
- one job per runner instance
- no host Docker socket mounted into job containers unless you accept container escape risk
- no production network access by default
- short-lived registration tokens and tightly controlled runner groups
- patched base images built by automation, not manually updated machines
--privileged job containers and host Docker access are common because they make nested builds easy. They also effectively grant host control. If you need Docker builds, prefer rootless builders, remote build services, or a dedicated high-risk runner pool.
Observability and lifecycle are operational features
Track queue time, job duration, runner online count, failure rate, and image age. Alert on runners that have been online too long — that usually means the autoscaler is reusing instances. Patch base images regularly and expire old images. Runner labels should describe capabilities truthfully: gpu, arm64, linux, private-network. Do not encode security policy in labels alone; runner groups and repository restrictions enforce it.
Field notes
- Fork pull requests plus self-hosted runners is a dangerous combination; require approval for outside collaborators and keep secrets unavailable.
- The runner service user should not be root on a machine that matters.
- Clean shutdown matters: canceled jobs can leave processes and temporary credentials behind, which is another reason to destroy the instance.
- Cost comparisons must include patching, monitoring, idle capacity, and incident response — not just VM price per minute.
Was this lesson helpful?