Sub topic 1
What a runner is and how it picks up jobs
A GitHub Actions workflow is only a description of work. A runner does the work. This chapter explains what a runner is, how it connects to GitHub, and how a queued job ends up on one particular machine. The rest of the tutorial builds on this model. Once you know how a job reaches a runner, it is easier to see what a reused runner leaves behind.
Prerequisites
This chapter assumes you already have the following:
- Basic GitHub Actions workflow syntax:
on,jobs,steps, andruns-on. - Comfort with a Linux shell, including running scripts and reading process output.
- A basic understanding of containers or virtual machines.
- Familiarity with Git and pull requests.
You do not need to have installed a self-hosted runner before. You also do not need to know anything about runner security yet. Later chapters cover that.
What a runner is
A runner is a machine that runs the jobs of a workflow. The machine can be a cloud VM, a physical server, a container, or a laptop. What turns it into a runner is a small program installed on it, the runner application.
The runner application is open source (the actions/runner repository) and is written in C# on .NET. It is a self-contained download, so you do not need to install .NET yourself. It has two main parts:
- Runner.Listener is the long-lived process. It talks to GitHub, waits for work, and reports status.
- Runner.Worker is a short-lived process. The listener starts one worker for each job. The worker downloads actions, runs each step, and streams logs back to GitHub.
When you unpack the runner, you will see these scripts:
| File | Purpose |
|---|---|
| `config.sh` | Registers the runner with GitHub and writes local configuration |
| `run.sh` | Starts the listener in the foreground |
| `svc.sh` | Installs and controls the runner as a system service (Linux) |
| `_work/` | The working directory where each job checks out code (created on first use) |
The runner does exactly one job at a time. If you want four jobs to run in parallel on one host, you need four runner instances. Each one needs its own directory and its own registration.
How the runner connects to GitHub
The runner never accepts inbound connections. Instead, the listener opens an outbound HTTPS connection to GitHub and asks for work. This is long polling. The request stays open until GitHub has a message for the runner or the request times out, and then the runner asks again.
This design has practical consequences:
- The host needs outbound access to GitHub on port 443. It does not need a public IP address, an open port, or a firewall rule that allows inbound traffic.
- A runner behind NAT or a corporate proxy works as long as it can reach GitHub.
- GitHub cannot push work to a runner that is offline. The job waits in the queue.
The life of a job
Follow one job from push to finish.
- A workflow run starts because of an event, such as a push or a pull request.
- GitHub reads the workflow and creates one job for each entry under
jobs. A job whoseneedsare not yet satisfied waits. A job with no pending dependencies is queued. - GitHub looks at the job's
runs-onvalue and finds the registered runners that match it. - An idle, online runner in that set receives the job through its open polling session.
- The listener starts a worker. The worker runs the steps in order and sends log lines back as they are produced.
- The job finishes with a result, and the worker exits. The listener goes back to polling.
The following diagram shows the exchange between the pieces.
The listener decides nothing about which job it gets. GitHub makes that choice on its side. The runner only tells GitHub that it is online and idle, and what labels it carries.
What the worker does on the host
The worker runs on your machine as the same operating system user that started the runner. That has two consequences you should keep in mind.
- Every
run:step is executed by a shell as that user. Any step can read files that user can read and run any command that user can run. - The job's working files live under the runner's
_workdirectory. The default behavior is to leave them there after the job. The next job on the same runner starts in the same tree.
For each job the worker also does the following:
- It downloads the actions that the job uses (for example
actions/checkout) and caches them under the runner directory. - It receives the job's secrets and environment variables from GitHub and passes them to the steps that use them.
- It receives a short-lived
GITHUB_TOKENscoped by the workflow'spermissions. - It runs any container actions or job containers through Docker, which must be installed on the host for those features.
Software that is already on the host, such as compilers, SDKs, and Docker, is available to every job. GitHub-hosted runners come with a large preinstalled toolset. A self-hosted runner has only what you put on it.
Matching jobs to runners
The runs-on key is a list of labels. A job goes only to a runner that carries every label in the list. Labels are case-insensitive for matching purposes.
Every self-hosted runner gets three kinds of default labels at registration:
self-hosted, which marks it as not GitHub-hosted.- The operating system:
linux,windows, ormacOS. - The architecture:
x64,arm, orarm64.
You can add custom labels at registration time. Labels are plain strings that you choose. GitHub does not verify what they mean.
Here is a workflow that targets a Linux x64 self-hosted runner.
name: build
on: push
jobs:
build:
runs-on: [self-hosted, linux, x64]
steps:
- uses: actions/checkout@v4
- run: uname -a
- run: whoamiThe uname -a and whoami steps are useful in a first test. They show which host ran the job and which operating system user the steps ran as.
If you write runs-on: ubuntu-latest, the job goes to a GitHub-hosted runner instead. A label such as ubuntu-latest means something to GitHub's own fleet. Self-hosted runners do not match it unless you deliberately gave a runner that label, which is a bad idea because it makes routing ambiguous.
What happens when nothing matches
A job that matches no runner does not fail right away. It stays queued. In the Actions UI you will see it as "Waiting for a runner to pick up this job". Three situations cause this, and they look the same from the outside:
- No registered runner has all of the requested labels. A typo in a label is the most common cause.
- Matching runners exist but are all offline, because the service stopped or the host is down.
- Matching runners exist and are online but all busy with other jobs.
A queued job does not wait forever. GitHub eventually fails jobs that no runner picks up, so a long outage turns into failed runs. When a job sits queued, check these in order:
- Compare the
runs-onlabels against the labels shown for the runner in the repository's or organization's runner settings. - Check whether the runner shows as Idle, Active, or Offline.
- Check the access rules that limit which repositories can use the runner. The chapter on runner groups covers them.
Checking a runner locally
You can start a configured runner in the foreground and watch it connect.
cd actions-runner
./run.shA healthy start prints lines like these, in this order:
√ Connected to GitHub
Current runner version: '...'
Listening for JobsWhen a job arrives, the output adds a line such as Running job: build, and after it ends, Job build completed with result: Succeeded. The runner then goes back to Listening for Jobs. That return to listening is the behavior to remember. A normal runner does not exit after a job. It stays registered and takes the next one on the same host, with the same disk and the same user. The next chapters explain why that matters.
Automatic updates
The runner application updates itself. If GitHub releases a newer runner version, the service can tell the listener to download it and restart. A runner that falls too far behind the minimum supported version can be refused jobs until it is updated. For a single long-lived host this is usually invisible. For fleets that build runner images in advance, it means a stale image will spend its first moments updating. You will meet this again when we discuss operating a fleet.
Common mistakes at this stage
- Expecting parallel jobs from one runner. One runner process takes one job at a time. Parallelism needs more runner instances.
- Using only
self-hostedinruns-on. This matches every self-hosted runner you own, including ones on a different OS. Add the OS and architecture labels, and a custom label for the pool you mean. - Opening inbound ports for the runner. It is not needed. The runner dials out.
- Assuming a clean machine. Nothing resets the host between jobs unless you build that in.
Exercise
A workflow job declares runs-on: [self-hosted, linux, arm64]. Your only registered runner has the labels self-hosted, linux, x64, and gpu. It is online and idle. What happens to the job, and what is the likely fix?
Show answer
The job stays queued with the message that it is waiting for a runner. The runner is missing the arm64 label, and a job only goes to a runner that carries every label in runs-on. The runner's x64 label does not match arm64. The fix is to change runs-on to match the runner ([self-hosted, linux, x64]), or to register a runner on an arm64 host.
Exercise
Your runner host sits in a private network with no public IP address and a firewall that blocks all inbound traffic but allows outbound HTTPS. Will it receive jobs? Explain the mechanism.
Show answer
Yes. The Runner.Listener opens an outbound HTTPS session to GitHub and long-polls for work. GitHub delivers the job message on that connection, so no inbound port or public address is needed. Only outbound access to GitHub on port 443 is required.
Exercise
After a job finishes on a normally configured self-hosted runner, what does the listener do, and what is left on the host for the next job?
Show answer
The worker process exits, and the listener goes back to polling for the next job. The runner stays registered. The host keeps everything the job left behind, including the _work directory, any files the steps wrote, installed tools, and Docker images, and the next job runs as the same operating system user.