</>

Technology

GitHub Actions

Difficulty

Beginner

Interview Question

What are GitHub Actions runners? What is the difference between GitHub-hosted and self-hosted runners?

Answer

GitHub Actions Runners

A runner is the machine (VM or container) that executes the steps in a job. Every job gets a fresh runner by default.

GitHub-Hosted Runners

Managed by GitHub — free for public repos, 2000 min/month for private.

YAML
jobs:
  build:
    runs-on: ubuntu-latest      # Latest Ubuntu LTS
    # or:
    runs-on: ubuntu-22.04       # Specific Ubuntu version
    runs-on: windows-latest     # Windows Server
    runs-on: windows-2022
    runs-on: macos-latest       # macOS (most expensive minutes)
    runs-on: macos-14

What's Pre-installed on ubuntu-latest

YAML
- Java (multiple versions via setup-java)
- Node.js (multiple versions)
- Python 3.x
- Maven, Gradle
- Docker
- Chrome, Firefox (for headless Selenium/Cypress)
- git, curl, wget, jq
- AWS CLI, Azure CLI, GCP SDK

Check Installed Software

YAML
steps:
  - run: java -version
  - run: mvn -version
  - run: node --version
  - run: google-chrome --version
  - run: docker --version

Self-Hosted Runners

Your own machine registered with GitHub. Used when you need:

  • Access to private network / internal services
  • Specific hardware (GPU, arm64)
  • Custom pre-installed tools
  • High usage (cost savings vs GitHub-hosted minutes)

Register a Self-Hosted Runner

Bash
# 1. Go to: Repo → Settings → Actions → Runners → New self-hosted runner
# 2. Choose OS, download runner package
# 3. Configure and start:

./config.sh --url https://github.com/org/repo --token YOUR_TOKEN
./run.sh   # starts the runner (or install as service)

Use Self-Hosted Runner in Workflow

YAML
jobs:
  test:
    runs-on: self-hosted           # any self-hosted runner
    # or with labels:
    runs-on: [self-hosted, linux, selenium]   # runner with these labels
    runs-on: [self-hosted, windows, gpu]

Label Your Runners

Bash
# Add labels when registering
./config.sh --url ... --token ... --labels "linux,selenium,chrome"

Comparison

GitHub-HostedSelf-Hosted
SetupZeroInstall runner agent
CostFree (public) / Minutes (private)Infrastructure cost
MaintenanceGitHub managesYou manage OS, updates
NetworkPublic internet onlyAccess internal systems
HardwareFixed (2 CPU, 7GB RAM)Your spec
SecurityEphemeral (fresh each job)Persistent — careful with secrets
Best forMost projectsPrivate network, custom env

Docker Container Runner

YAML
jobs:
  test:
    runs-on: ubuntu-latest
    container:
      image: maven:3.9-openjdk-17   # run job inside this container
      options: --user root
    steps:
      - uses: actions/checkout@v4
      - run: mvn test  # runs inside Maven container

Follow AutomateQA

Related Topics