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), use a Linux shell, and know the basics of virtual machines and containers. It compares the two kinds of runner. It also gives you criteria for deciding when self-hosting is worth the work. Registration, labels, and the security problems of long-lived runners are covered in later chapters.
The two kinds of runner
A runner is the machine that executes the steps of one job. The runner application on that machine polls GitHub for queued jobs, runs them, and streams logs back. Every job runs on exactly one runner. The two kinds differ in who owns the machine.
- A GitHub-hosted runner is a virtual machine that GitHub creates, maintains, and destroys. You select it with a label such as
ubuntu-latest. - A self-hosted runner is a machine you provide and operate. It can be a physical server, a cloud VM, or a container. You install the runner application on it and connect it to GitHub.
The workflow syntax is the same for both. Only the runs-on value changes.
name: where-am-i
on: workflow_dispatch
permissions:
contents: read
jobs:
hosted:
runs-on: ubuntu-latest
steps:
- run: echo "env=${{ runner.environment }} os=${{ runner.os }} arch=${{ runner.arch }}"
self-hosted:
runs-on: [self-hosted, linux, x64]
steps:
- run: echo "env=${{ runner.environment }} os=${{ runner.os }} arch=${{ runner.arch }}"The runner.environment context prints github-hosted for the first job and self-hosted for the second. The second job stays queued until a self-hosted runner with all three labels is online. If none is online, it waits instead of failing.
What GitHub-hosted runners give you
GitHub-hosted runners are the default for good reasons.
- A fresh machine for every job. Each job starts on a clean VM that is deleted afterward. Files, processes, and credentials from one job cannot reach the next.
- Maintained images. GitHub builds the images and keeps the operating system, compilers, and common tools patched and current.
- No capacity planning. You do not size a fleet or watch for idle machines. Jobs start when capacity exists.
- No inbound exposure. Nothing in your network is reachable from the runner unless you build a path to it.
The costs of hosted runners are mostly limits on what you can control:
- The hardware choices are fixed. Standard runners have a set size, and larger runners cost more.
- Hosted runners sit outside your network. They cannot reach a private database or an internal package registry without extra networking.
- The image contents are chosen by GitHub. You can install tools in each job, but that costs time on every run.
- Usage is billed or counted against a quota for private repositories. Standard runners are free for public repositories. Check GitHub's current pricing page for the exact rules, because they change.
What self-hosting gives you
Teams self-host when a hosted runner cannot meet a concrete requirement. The common reasons are below.
- Private network access. The job must reach a system that is not on the public internet, such as an internal artifact store, a staging database, or a deployment target.
- Special hardware. You need GPUs, Arm machines, large amounts of memory, many CPU cores, or a specific device attached to the host.
- Custom environment. The build needs a particular operating system version, licensed software, or a large toolchain that you want preinstalled instead of downloaded each run.
- Cost at scale. If you run many job-minutes on hardware you already own, or on cheaper cloud capacity, self-hosting can cost less. Include the engineering time to operate the fleet in your comparison.
- Compliance and data residency. Rules may require that code and build artifacts stay on infrastructure in a given region or under your control.
- Longer jobs. GitHub documents a longer maximum job time for self-hosted runners than for hosted ones (6 hours hosted, 5 days self-hosted at the time of writing).
Two points about how the connection works. The runner makes outbound HTTPS connections to GitHub and long-polls for work, so you do not open inbound ports. The runner application also updates itself, and GitHub stops sending jobs to runners that fall too far behind the supported version.
Side-by-side comparison
| Aspect | GitHub-hosted | Self-hosted |
|---|---|---|
| Who owns the machine | GitHub | You |
| State between jobs | None. A new VM per job | Whatever you design. A default runner keeps its disk |
| Operating system patches | GitHub | You |
| Tools preinstalled | Set by GitHub's image | Anything you install |
| Hardware | Fixed menu of sizes | Anything you can provide |
| Access to private network | Needs extra setup | Natural, if the host is inside it |
| Capacity | GitHub scales it | You scale it, or a job queues |
| Billing | Minutes, with quotas and prices | Your infrastructure costs, plus operating effort |
| Main security burden | Low, on your side | High. You own isolation and cleanup |
The row about state between jobs is the one this tutorial is built around. A GitHub-hosted runner is clean by construction. A self-hosted runner is not, unless you make it so.
The hidden cost: you inherit the isolation GitHub gave you
When you move to self-hosted runners, you also take over work that GitHub did silently. Hosted runners destroy the VM after each job. A self-hosted runner installed the usual way keeps running after a job finishes and accepts the next one on the same machine. That has three consequences:
- Files a job leaves in the work directory, caches, or temporary folders are visible to later jobs.
- Credentials written to disk, such as a cloud config file or an SSH key, can outlive the job that created them.
- Processes started by a job, such as a background service, can keep running after the job ends.
You also take over patching, monitoring, capacity, and log retention. These are the recurring costs of self-hosting, and teams often underestimate them. The later chapters show how ephemeral runners remove the first group of problems by restoring the "fresh machine per job" property on your own infrastructure.
A decision flow
Start from the requirement, not from the preference. Use a hosted runner unless something forces your hand.
Hosted options may cover part of a requirement. GitHub offers larger hosted runners and can attach hosted runners to a private network in some plans. Check these before you take on a fleet. A mixed setup is common: most jobs run on hosted runners, and only the few that need special access run on self-hosted ones.
Choosing per job, not per organization
The choice is made in each job's runs-on, so you can split a pipeline. Unit tests that need nothing special run on a hosted runner. The deployment job that needs a private network runs on a self-hosted one.
name: build-and-deploy
on:
push:
branches: [main]
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: make test
deploy:
needs: test
runs-on: [self-hosted, linux, x64]
steps:
- uses: actions/checkout@v4
- run: ./scripts/deploy.shThis keeps the self-hosted footprint small. It also keeps the code that runs on your network limited to jobs you chose to place there. The permissions block limits the GITHUB_TOKEN to read access, which is a sensible default for any runner.
Common mistakes
- Self-hosting to save money without counting operating time. Include engineer hours, idle capacity, and incident costs in the comparison.
- Treating a self-hosted runner as equivalent to a hosted one. The same workflow can behave differently because tools, versions, and leftover files differ. Do not assume a tool exists on the host.
- Putting a runner on a machine that holds other valuable things. A runner executes code from your workflows. Anything the runner's user can reach, a job can reach.
- Forgetting that a missing runner queues jobs silently. If the labels match no online runner, the job waits. Monitor queue time.
Key takeaways
- A runner executes one job at a time. Hosted runners are GitHub's VMs, and self-hosted runners are yours.
- Hosted runners are clean per job and maintained for you. Self-hosted runners offer private network access, custom hardware, and control, at the price of operating them.
- Teams self-host for network access, hardware, environment control, cost at scale, compliance, or long jobs.
- The default self-hosted runner is not clean between jobs. That gap is what the rest of this tutorial closes.
Exercise
A team's integration tests must connect to a database that is reachable only from inside their corporate network. The unit tests need nothing special. Which runner type would you choose for each job, and what is the main new responsibility the team takes on for the integration job?
Show answer
Run the unit tests on a GitHub-hosted runner (for example ubuntu-latest), because they need no special access and get a clean VM per job. Run the integration tests on a self-hosted runner inside the corporate network so it can reach the database. The team now owns that runner's patching, capacity, monitoring, and, most importantly, its isolation: a default self-hosted runner keeps files and credentials between jobs, so they must clean or recreate it.
Exercise
A job with runs-on: [self-hosted, linux, x64] sits in the queue for an hour and never starts, and no error appears. Give two likely causes.
Show answer
No online self-hosted runner carries all three labels (self-hosted, linux, x64), or the matching runners are all busy with other jobs. A job that has no matching available runner stays queued instead of failing. Other possible causes are runners that are offline, or runners that are not permitted to serve this repository.