Sub topic 2
GitHub-hosted versus self-hosted runners: why teams self-host
This chapter assumes you can read a GitHub Actions workflow (on, jobs, steps, runs-on), work in a Linux shell, and know roughly what a container or virtual machine is. It compares the two kinds of runner and explains why teams choose to run their own.
Two places a job can run
A runner is the machine that executes the steps of one job. Every job in a workflow needs one. There are two kinds:
- A GitHub-hosted runner is a virtual machine that GitHub provisions, patches, and destroys for you.
- A self-hosted runner is a machine you own and operate. It runs the runner application, which connects to GitHub and waits for work.
The workflow file chooses between them with runs-on. A value such as ubuntu-latest selects a GitHub-hosted image. A list that starts with self-hosted selects your own machines.
jobs:
build-hosted:
runs-on: ubuntu-latest
build-own:
runs-on: [self-hosted, linux, x64]What GitHub-hosted runners give you
GitHub-hosted runners need almost no work from you. The main properties are:
- Each job starts on a clean virtual machine, and the machine is discarded when the job ends. No files or processes carry over to the next job.
- GitHub maintains the operating system image and preinstalled tools.
- There is nothing to scale. GitHub starts a machine for each job.
- You pay for usage, or use the minutes included in your plan.
The clean start matters for later chapters. It is the property you will need to rebuild if you self-host.
Why teams self-host
Teams move to self-hosted runners when the hosted option cannot meet a specific need. Common reasons:
| Reason | Example |
|---|---|
| Network access | Jobs must reach a database, artifact store, or service inside a private network. |
| Hardware | Builds need a GPU, a large amount of memory, or a CPU architecture that hosted images do not offer. |
| Custom software | The build needs a licensed toolchain or a large preinstalled dependency set. |
| Cost at scale | Very high job volume can be cheaper on infrastructure you already pay for. |
| Compliance | Rules require that code is built on machines in a particular location or under your control. |
Each reason is a real benefit. None of them requires the runner to be long-lived, which is the assumption that causes the problems described later in this tutorial.
What you take on
When you self-host, work that GitHub did for you becomes yours:
- Patching the operating system and the runner application. Out-of-date runners can fail to receive jobs.
- Providing capacity. If every runner is busy, jobs wait in the queue.
- Cleaning up after each job. Nothing resets the machine unless you build that step.
- Securing the machine, including what code is allowed to run on it and what credentials it can reach.
The fourth item has the highest stakes. A hosted runner is isolated from your network by default. A self-hosted runner often sits inside it.
Choosing between them
Start with hosted runners. Move a job to self-hosted only when one of the reasons in the table applies to that job. Many teams use both: hosted runners for ordinary tests, and a small self-hosted pool for jobs that need private network access or special hardware.
When you do self-host, the design goal is to get the clean-start behavior of hosted runners back. The rest of this tutorial covers how: registration, labels, ephemeral runners, just-in-time configuration, and autoscaling.
Exercise
A team's integration tests must call a database that is reachable only from their private network. Which kind of runner fits, and which property of GitHub-hosted runners should they try to reproduce on it?
Show answer
A self-hosted runner fits, because it can sit inside the private network. They should reproduce the clean start of hosted runners, where each job gets a fresh machine that is discarded afterwards, so no files or credentials carry over between jobs.
Exercise
Name two tasks that move from GitHub to your team when you switch a job from a hosted runner to a self-hosted one.
Show answer
Any two of: patching the operating system and runner application, providing enough capacity so jobs do not queue, cleaning the machine between jobs, and securing the machine and the credentials it can reach.