What is a GitHub Actions runner and what is the difference between hosted and self-hosted runners?
Understand what a GitHub Actions runner is and the trade-offs between GitHub-hosted and self-hosted runners for control, cost, hardware, and security.
Expected Interview Answer
A GitHub Actions runner is the machine that executes the jobs in a workflow. GitHub-hosted runners are ephemeral virtual machines provisioned and maintained by GitHub, while self-hosted runners are machines you own, configure, and register yourself.
GitHub-hosted runners spin up a fresh, clean VM for every job, come preinstalled with common tooling, and are billed by usage minutes with no maintenance burden. Self-hosted runners run on your own hardware or cloud, giving you control over the OS, installed software, network access, and hardware such as GPUs, but you are responsible for patching, scaling, and securing them. Self-hosted runners persist state between jobs unless you make them ephemeral, which introduces cleanup and security considerations.
- Hosted runners need zero maintenance and start clean each job
- Hosted runners come preloaded with popular tools
- Self-hosted runners allow custom hardware like GPUs
- Self-hosted runners can reach private internal networks
- Self-hosted runners can reduce cost at high volume
AI Mentor Explanation
A runner is the ground crew that actually plays out your match instructions. A hosted runner is like renting a fully prepared international stadium for one game, then leaving — the board maintains the pitch and gear. A self-hosted runner is your own club ground: you control the pitch, the nets, and any special turf, but you must mow, roll, and secure it yourself between every match.
Step-by-Step Explanation
Step 1
Understand the runner's role
The runner is the agent that picks up a queued job and executes its steps.
Step 2
Choose hosted for simplicity
Set runs-on to a hosted image like ubuntu-latest to get a fresh, maintained VM per job.
Step 3
Choose self-hosted for control
Register your own machine, install the runner application, and label it for custom hardware or network access.
Step 4
Target the runner
Use runs-on with the self-hosted label plus any custom labels to route jobs to the right machine.
Step 5
Secure self-hosted runners
Prefer ephemeral runners and avoid using them on public repository forks to prevent code execution risks.
What Interviewer Expects
- Clear definition of what a runner does
- Knowing hosted runners are ephemeral and maintained by GitHub
- Understanding self-hosted runners need patching and scaling
- Awareness of security risks with self-hosted runners on forks
- Reasons to pick one over the other, such as GPUs or cost
Common Mistakes
- Thinking self-hosted runners are automatically cleaned between jobs
- Recommending self-hosted runners for public fork PRs without caveats
- Believing hosted runners persist state between jobs
- Ignoring maintenance and scaling burden of self-hosted runners
- Confusing runners with the workflow file itself
Best Answer (HR Friendly)
“A runner is simply the computer that actually carries out the automated tasks in GitHub Actions. GitHub can provide these machines for you, cleaned up after each job, or you can supply your own machines when you need special hardware or access to internal systems, at the cost of maintaining them yourself.”
Code Example
jobs:
test-on-hosted:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm test
build-on-self-hosted:
runs-on: [self-hosted, linux, gpu]
steps:
- uses: actions/checkout@v4
- run: ./build-with-gpu.shFollow-up Questions
- Why are self-hosted runners risky on public repositories?
- What is an ephemeral self-hosted runner?
- How does GitHub bill for hosted runner minutes?
- How do runner labels route jobs to specific machines?
- How would you autoscale a fleet of self-hosted runners?
MCQ Practice
1. What is the key characteristic of a GitHub-hosted runner?
GitHub-hosted runners provision a clean, ephemeral virtual machine for each job and are maintained by GitHub.
2. Which is a valid reason to choose a self-hosted runner?
Self-hosted runners let you use specialized hardware like GPUs and reach internal networks that hosted runners cannot.
3. What is a major security concern with self-hosted runners?
Self-hosted runners can persist state and run untrusted code from forks, so they should not be used on public repositories without safeguards.
Flash Cards
What is a runner? — The machine that executes the jobs and steps defined in a workflow.
GitHub-hosted runner — An ephemeral, preconfigured VM provisioned fresh per job and maintained by GitHub.
Self-hosted runner — Your own machine, registered to GitHub, giving custom hardware and network access but requiring maintenance.
Self-hosted security risk — They can run untrusted fork code and persist state, so avoid them on public repos and prefer ephemeral runners.
Continue Learning
Related Interview Questions
What is GitHub Actions and how do workflows, jobs, and steps work?
easy
What is CI/CD and what problems does it solve in software delivery?
easy
What is the difference between continuous integration, continuous delivery, and continuous deployment?
medium
What is a CI/CD pipeline and what are its typical stages?
medium