Sub topic 1
What a runner is and how it picks up jobs
Prerequisites
This chapter assumes you know:
- Basic GitHub Actions workflow syntax:
on,jobs,steps, andruns-on. - How to use a Linux shell.
- What a container or virtual machine is.
- Git and pull requests.
What a runner is
A runner is a machine that executes the jobs in a GitHub Actions workflow. The machine runs the GitHub runner application, a small program that connects to GitHub, waits for work, and runs the steps of one job at a time.
GitHub does not run your steps itself. It decides which jobs need to run, queues them, and hands each job to a runner. The runner does the actual work: it checks out code, runs shell commands, and reports logs and results back.
A runner can be a GitHub-hosted virtual machine or a machine you manage yourself. A self-hosted runner is the second kind. It can be a physical server, a cloud VM, or a container. The application is the same in both cases. What differs is who owns the machine and what is left on it after a job.
How a job reaches a runner
The runner application opens an outbound HTTPS connection to GitHub and polls for work. GitHub never connects inward to your machine, so you do not need to open inbound firewall ports.
The flow looks like this:
- An event, such as
pull_request, triggers a workflow. - GitHub reads each job's
runs-onvalue and queues the job. - An idle runner whose labels match asks GitHub for work.
- GitHub sends the job definition and a short-lived token for that run.
- The runner executes the steps and streams logs back.
- When the job ends, the runner reports a result and becomes idle again.
A runner handles one job at a time. If five jobs are queued and you have two matching runners, two jobs run and three wait. If no matching runner is online, the job stays queued until one appears.
Routing with runs-on
The runs-on key is the only link between a job and a runner. Here is a workflow that targets self-hosted machines:
name: test
on: pull_request
permissions:
contents: read
jobs:
test:
runs-on: [self-hosted, linux, x64, ephemeral]
steps:
- uses: actions/checkout@v4
- run: make testA runner is eligible only if it carries every label in the list. Here that means self-hosted, linux, x64, and ephemeral. A runner that has the first three but not ephemeral is skipped. Later chapters cover labels in detail. For now, remember that a missing label is the most common reason a job sits in the queue forever.
The permissions block limits the GITHUB_TOKEN that the job receives. Here it grants read access to repository contents and nothing else. This is a good habit on any runner, and it matters more on self-hosted ones.
What a job leaves behind
When a job runs, it works inside the runner's directories. The runner creates a _work folder and checks the repository out into it. Steps can also write to the home directory, install packages, start background processes, and cache files.
On a GitHub-hosted runner, the VM is discarded after the job, so none of this survives. On a self-hosted runner that stays online, everything the job wrote is still there when the next job starts. That includes files, environment changes, and credentials that a step wrote to disk. This is the core problem the rest of the tutorial addresses.
Summary
- A runner is a machine running the runner application, which polls GitHub and runs one job at a time.
- Connections are outbound, so the runner needs no inbound ports.
runs-onselects runners by label, and a runner must carry all listed labels.- Without cleanup, a self-hosted runner keeps the files and state of every earlier job.
Exercise
A job uses runs-on: [self-hosted, linux, gpu]. Your only online runner has the labels self-hosted, linux, and x64. What happens to the job, and why?
Show answer
The job stays queued. A runner must carry every label in runs-on, and this runner lacks gpu. The job runs only after a runner with all three labels comes online.
Exercise
Why does a self-hosted runner not need an open inbound port, and what does this tell you about who starts the communication?
Show answer
The runner application makes outbound HTTPS connections to GitHub and polls for jobs. The runner starts the communication, and GitHub replies with job data, so no inbound connection is needed.