GitHub-Hosted vs Self-Hosted

Earn 25 points (50 with Pro) in two steps

  1. ① Read through the lesson — each section gets a ✓ as you scroll through it.
  2. ② When every section has a ✓, tap Complete lesson.

0 of 11 read · keep scrolling

✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro

Mastering GitHub Runners: GitHub-Hosted vs. Self-Hosted

Introduction: The Engine Room of Automation

GitHub Actions has revolutionized how developers automate their workflows. Whether it is running unit tests, building container images, or deploying code to production, the "runner" is the actual machine that executes the commands defined in your workflow files. A runner is essentially a server—virtual or physical—that listens for available jobs, runs them, and reports the results back to GitHub.

Choosing the right type of runner is one of the most critical architectural decisions you will make when setting up your CI/CD pipeline. The choice between GitHub-hosted runners and self-hosted runners directly impacts your security posture, your operational overhead, your budget, and the speed at which your code moves from development to production.

In this lesson, we will peel back the layers of how these runners operate. We will look at the trade-offs, the configuration requirements, and the best practices for maintaining a healthy automation environment. By the end of this guide, you will have the knowledge to decide exactly which runner strategy fits your team’s specific technical and operational needs.


Not read yet

Understanding GitHub-Hosted Runners

GitHub-hosted runners are virtual machines managed and maintained by GitHub. When you trigger a workflow, GitHub automatically provisions a clean, ephemeral instance for your job. Once the job completes, the instance is discarded.

How They Work

When you use a standard GitHub-hosted runner, you don't worry about patching operating systems, updating software, or managing networking. GitHub maintains a set of images (Ubuntu, Windows, and macOS) that come pre-installed with a vast collection of tools, including common programming languages, build tools, and CLI utilities.

Advantages of GitHub-Hosted Runners

  • Zero Maintenance: You never have to worry about disk space, OS updates, or security patches for the underlying runner.
  • Built-in Security: Because the runners are ephemeral and destroyed after every job, you don't have to worry about residual data or persistent threats from previous builds.
  • High Scalability: GitHub handles the scaling for you. If you trigger 50 jobs simultaneously, GitHub automatically provisions 50 runners.
  • Predictable Environments: Every build starts with a known, consistent environment, reducing the "it works on my machine" syndrome.

Limitations

  • Cost: While GitHub provides a free tier for public repositories, private repositories have limited minutes. Scaling up can become expensive quickly.
  • Network Access: GitHub-hosted runners are on the public internet. If your build needs to access a private database or an internal server behind a firewall, you will need to set up complex networking solutions like VPNs or GitHub Actions IP allow-listing.
  • Customization Constraints: While you can install additional software during the workflow, doing so every time adds latency to your jobs.

Callout: The Ephemeral Nature of Runners The most important characteristic of GitHub-hosted runners is that they are ephemeral. This means they are "disposable." You cannot rely on a file created in Job A being available in Job B unless you explicitly use artifacts or caches. This design forces developers to write cleaner, more modular workflows that do not rely on side effects or persistent state on the build server.


Not read yet

Understanding Self-Hosted Runners

Self-hosted runners are machines that you own, manage, and host yourself. These can be physical servers in your data center, virtual machines in your own AWS or Azure VPC, or even a laptop sitting under your desk. You install the GitHub runner software on these machines, and they connect to GitHub to receive jobs.

Why Choose Self-Hosted?

The primary driver for self-hosted runners is control. When you host your own runners, you define the hardware specifications, the operating system configuration, and the security perimeter.

Advantages of Self-Hosted Runners

  • Performance: You can provision high-performance hardware with massive RAM and CPU counts to speed up heavy build processes.
  • Networking: Since the runner is inside your network, it can easily access private databases, internal APIs, and restricted resources without needing complex firewall rules.
  • Cost Efficiency: For teams with consistent, high-volume CI/CD needs, self-hosted runners often end up being cheaper than paying for GitHub-hosted minutes at scale.
  • Customization: You can pre-install specialized proprietary software, hardware drivers, or specific versions of tools that are not available on standard images.

Disadvantages

  • Operational Overhead: You are responsible for everything—security patching, disk cleanup, monitoring runner health, and scaling.
  • Security Risk: If a runner is compromised, the attacker has a foothold inside your private network. You must treat these runners as sensitive production infrastructure.
  • State Accumulation: Because these runners are persistent, they can accumulate "junk" over time (large logs, temporary files, docker images), which can cause builds to fail if not managed properly.

Not read yet

Comparison Table: GitHub-Hosted vs. Self-Hosted

Feature GitHub-Hosted Self-Hosted
Maintenance Managed by GitHub Managed by You
Scaling Automatic Requires manual/auto-scaling setup
Network Access Public Internet Internal/Private Network
Cost Model Pay-per-minute Hardware/Cloud costs + Ops time
Security Ephemeral/Isolated Persistent/Requires hardening
Setup Time Immediate Requires installation and registration

Implementing Self-Hosted Runners: Step-by-Step

Setting up a self-hosted runner involves installing the runner application and registering it with your GitHub organization or repository.

Step 1: Create the Runner in GitHub

  1. Navigate to your repository or organization settings.
  2. Select Actions > Runners.
  3. Click New self-hosted runner.
  4. Choose the operating system and architecture.

Step 2: Install the Runner Software

GitHub will provide a set of commands specific to your platform. For a Linux machine, the process typically looks like this:

# Create a folder for the runner
mkdir actions-runner && cd actions-runner

# Download the latest runner package
curl -o actions-runner-linux-x64-2.300.0.tar.gz -L https://github.com/actions/runner/releases/download/v2.300.0/actions-runner-linux-x64-2.300.0.tar.gz

# Extract the installer
tar xzf ./actions-runner-linux-x64-2.300.0.tar.gz

# Configure the runner
./config.sh --url https://github.com/your-org/your-repo --token <YOUR_TOKEN>

Step 3: Run as a Service

Running the runner in your terminal is fine for testing, but for production, you must run it as a service so it survives reboots.

# Install the service
sudo ./svc.sh install

# Start the service
sudo ./svc.sh start

Note: Always use a dedicated service account with limited permissions to run the GitHub Actions runner process. Never run the runner as the root user, as a compromised build script could grant an attacker full control over the host machine.


Not read yet

Best Practices for Managing Runners

1. Labeling Your Runners

Labels are essential for directing specific jobs to specific runners. If you have a runner with a GPU, you should label it as gpu-enabled.

jobs:
  build:
    runs-on: [self-hosted, gpu-enabled]
    steps:
      - run: ./run-gpu-intensive-task.sh

2. Disk Space Management

Self-hosted runners are prone to running out of disk space because build artifacts and Docker images accumulate. Implement a cron job to clean up the _work directory or prune unused Docker images regularly.

# Example cleanup script for a cron job
docker system prune -f
rm -rf /home/runner/actions-runner/_work/your-repo/your-repo/build/temp/*

3. Security Hardening

If you use self-hosted runners, treat them like a production database.

  • Keep the OS updated with the latest security patches.
  • Limit the runner's access to external networks using an egress firewall.
  • Ensure that only trusted repositories can use the runner (use Organization-level runners with restricted access if possible).

Callout: Scaling Self-Hosted Runners The biggest trap with self-hosted runners is manual scaling. You should not rely on a single "static" server. Instead, look into tools like "Actions Runner Controller" (ARC). ARC is a Kubernetes operator that automatically scales your runners based on the number of jobs in the queue, giving you the best of both worlds: self-hosted control with automatic scaling.


Not read yet

Common Pitfalls and How to Avoid Them

Pitfall 1: Leaking Secrets via Logs

When using self-hosted runners, developers sometimes accidentally output secrets or environment variables in logs. Because the runner is inside your network, a leaked credential could be far more damaging than on a GitHub-hosted runner.

  • Solution: Use GitHub’s built-in secret masking. Always use echo "::add-mask::value" for sensitive data.

Pitfall 2: Environment Drift

Over time, self-hosted runners become "special snowflakes" because developers manually install tools on them. This makes it impossible to recreate the build environment.

  • Solution: Use Infrastructure as Code (Terraform, Ansible, or Packer) to define your runner images. If a runner needs an update, replace the whole VM rather than patching it in place.

Pitfall 3: Ignoring Job Queues

If you don't have enough self-hosted runners, your jobs will sit in a "queued" state. This can delay critical deployments.

  • Solution: Monitor your queue depth. If your queue consistently stays above zero for long periods, it is time to add more capacity or investigate why jobs are taking so long to complete.

Not read yet

Deep Dive: When to Switch?

Many teams start with GitHub-hosted runners and eventually realize they need to migrate. Here are the specific indicators that you should consider moving to self-hosted runners:

  1. The "Network Gap": You spend more time configuring complex VPN tunnels or reverse proxies to let GitHub-hosted runners talk to your internal systems than you spend writing code.
  2. Resource Bottlenecks: Your builds consistently fail due to memory limits or disk space limits on GitHub’s standard runners, and the cost of "larger" GitHub runners is becoming prohibitive.
  3. Compliance Requirements: Your security team mandates that all CI/CD traffic must stay within a specific geographic region or on a specific, hardened network segment that GitHub-hosted runners cannot access.
  4. Hardware Acceleration: You need specialized hardware, such as FPGAs, specific GPU models, or proprietary hardware interfaces that are not provided by standard cloud images.

Not read yet

Operational Excellence: Monitoring and Maintenance

Regardless of which runner type you choose, monitoring is non-negotiable. For GitHub-hosted runners, you can monitor usage via the "Actions" tab in your organization settings. For self-hosted runners, you need to monitor the health of the host machine itself.

Key Metrics to Track

  • Runner Status: Is the runner currently 'online' and 'idle', or 'busy'?
  • Job Latency: How long does a job wait in the queue before it is picked up by a runner?
  • Job Failure Rate: Are jobs failing because of the code, or because the runner is crashing (e.g., OOM - Out of Memory)?
  • Resource Utilization: CPU and RAM spikes during builds can indicate that you need to optimize your build processes or upgrade your hardware.

Automating Maintenance

If you are using virtual machines for self-hosted runners, adopt the "Immutable Infrastructure" pattern. Instead of updating a runner, create a new machine image (AMI or VM template) with the updated software and replace the old runner. This ensures that every runner is in a known, clean state.

# Example logic for a cleanup script to run after every job
# You can use the 'post-job' action or a systemd timer
if [ -d "/tmp/build_artifacts" ]; then
  rm -rf /tmp/build_artifacts/*
fi

Not read yet

Security Considerations: The "Insider" Threat

Self-hosted runners are a major target for attackers. If a malicious actor manages to submit a Pull Request to your repository, they might try to execute code on your runner.

  • Never allow "public" access: Ensure your self-hosted runners are restricted to specific, trusted repositories.
  • Use Runner Groups: Use GitHub's "Runner Groups" to restrict which repositories can access specific runners. This prevents a low-priority project from consuming all the resources of your high-priority production runners.
  • Audit Logs: Regularly review the GitHub audit logs to see who is triggering workflows and which runners are being used.

Warning: Never use self-hosted runners for untrusted code. If you allow external contributors to submit PRs, those PRs should only be allowed to run on GitHub-hosted runners. If you run untrusted code on a self-hosted runner, the attacker could potentially extract your cloud credentials, access your internal network, or steal proprietary source code.


Not read yet

Advanced Configuration: Actions Runner Controller (ARC)

For teams using Kubernetes, the Actions Runner Controller (ARC) is the gold standard for self-hosted runners. It is a Kubernetes controller that manages the lifecycle of runners.

Why ARC?

  • Dynamic Scaling: ARC watches the GitHub API. If it sees 10 jobs pending, it instantly spins up 10 runner pods in your cluster. When the jobs finish, it kills the pods.
  • Declarative Setup: You define your runners in YAML. This means your runner configuration is stored in Git, just like your application code.
  • Resource Quotas: You can use Kubernetes namespaces and resource limits to ensure that your CI/CD runners do not starve your production applications of CPU and memory.
# Example ARC RunnerDeployment definition
apiVersion: actions.summerwind.dev/v1alpha1
kind: RunnerDeployment
metadata:
  name: example-runner
spec:
  template:
    spec:
      repository: my-org/my-repo

This approach removes the manual work of managing individual VMs and brings the runner management into the modern cloud-native era.


Not read yet

Summary of Key Takeaways

  1. Start with GitHub-Hosted: For most projects, the convenience, security, and zero-maintenance nature of GitHub-hosted runners make them the best starting point.
  2. Evaluate for Self-Hosted: Only move to self-hosted runners if you have a specific technical requirement, such as internal network access, specialized hardware, or significant cost savings at scale.
  3. Treat Runners as Infrastructure: Whether you use GitHub-hosted or self-hosted, treat your CI/CD environment as code. Use automation to provision, configure, and monitor your runners.
  4. Prioritize Security: Self-hosted runners are an extension of your internal network. Apply the same security rigor to them that you would apply to your production servers, including limiting access and avoiding root execution.
  5. Monitor Your Queues: Always keep an eye on job wait times. A slow CI/CD pipeline is a silent killer of developer productivity.
  6. Embrace Ephemerality: Wherever possible, ensure your runners are ephemeral. If you use self-hosted runners, use tools like ARC to ensure that pods are destroyed and recreated to prevent state accumulation and configuration drift.
  7. Use Labels Wisely: Strategic labeling allows you to route jobs to the right hardware, ensuring that resource-heavy tasks don't block lightweight tasks.

By mastering these concepts, you shift from being a passive user of automation to an architect of a reliable, scalable, and secure CI/CD engine. The choice between GitHub-hosted and self-hosted is not a "one-time" decision; it is a strategic balancing act that should evolve as your team and your infrastructure grow. Keep your runners clean, your network secure, and your scaling automated, and your development team will thank you for it.

Not read yet

Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.