GitHub Actions Self-Hosted Runners: Setup and Gotchas
When to use a self-hosted GitHub Actions runner, how to install it as a service on a Linux VM, and the security and maintenance gotchas to plan for.
A GitHub Actions self hosted runner is a small agent you install on your own machine that picks up workflow jobs from GitHub. Instead of running on a fresh GitHub-hosted VM, the job runs on your server, with your network access, your disks and your tools already installed.
I use self-hosted runners for deploys, scheduled content pipelines and builds that need to sit close to production. They are simple to install and easy to get subtly wrong. This post covers when they are worth it, the setup I use, and the gotchas that have cost me time.
TL;DR
Use a self-hosted runner when a job needs private network access, a persistent environment, special hardware or long runtimes. Install it under a dedicated user as a systemd service, label it, keep it off public repositories, and schedule cleanup of workspaces and caches. Treat the runner machine like production, because for deploy jobs it effectively is.
key takeaways
- Self-hosted runners make sense for deploys to private servers, long jobs, scheduled pipelines and work that needs specific hardware or network access.
- Install the runner as a systemd service under a dedicated non-root user so it survives reboots and has limited power.
- Never attach self-hosted runners to public repositories, because a pull request from a fork could run code on your machine.
- Runners keep state between jobs, so clean workspaces, prune caches and watch disk space or builds will fail in confusing ways.
When a self-hosted runner is worth it
GitHub-hosted runners are excellent for tests and builds that need nothing special. Reach for self-hosted when one of these is true:
| Situation | Why self-hosted helps |
|---|---|
| Deploying to a VM without opening SSH to the world | The runner lives on or next to the server and pulls jobs outbound over HTTPS |
| Scheduled pipelines that run for a long time | No per-minute billing pressure, and persistent caches speed reruns |
| Jobs needing private resources | Database replicas, internal APIs or VPC-only services are reachable |
| Heavy builds | A large VM with warm dependency caches beats a cold hosted runner |
| Multiple projects on one server | Several runners, each labeled, share one box |
The outbound-only connection is the underrated benefit. The runner polls GitHub, so you do not need inbound ports for CI, and your SSH can stay restricted to a bastion or your own IP.
Setup on a Linux VM
This is the sequence I use on Ubuntu. GitHub's self-hosted runner documentation has the canonical commands for your OS and architecture.
- Create a dedicated user, for example
runner, with no sudo by default. Grant narrow sudo rules later only if a job truly needs them (such as reloading Nginx). - Download the runner into a directory like
/home/runner/actions-runner-app1using the commands from the repo's Settings, Actions, Runners page. - Configure it with
./config.sh --url <repo-or-org> --token <token> --labels gcp,deploy,app1 --name app1-vm1. Labels are how workflows target the right machine. - Install as a service with
sudo ./svc.sh install runnerandsudo ./svc.sh start. Now it restarts on reboot and logs to journald. - Install toolchains the jobs need: Node via nvm, PM2, Python, Playwright browsers. Pin versions so jobs do not change behavior when the machine updates.
- Target it in workflows:
jobs:
deploy:
runs-on: [self-hosted, deploy, app1]
concurrency: deploy-app1
steps:
- uses: actions/checkout@v4
- run: npm ci && npm run build
- run: pm2 reload ecosystem.config.js
The concurrency key matters. Without it, two quick pushes can run overlapping deploys on the same server.
For parallel jobs, register multiple runners in separate directories. Each runner handles one job at a time.
Security rules I do not break
A self-hosted runner executes whatever the workflow file tells it to. That makes the workflow file part of your attack surface.
- Private repositories only. GitHub explicitly warns against self-hosted runners on public repos, since a fork's pull request could run arbitrary code.
- Non-root user. If a job is compromised, it should not own the machine.
- Scoped secrets. Use environment-level secrets with required reviewers for production deploys.
- Limit who can edit workflows. Branch protection and CODEOWNERS on
.github/workflows/stop a casual change from addingcurl | bash. - Separate runners per trust level. Do not let an experimental repo share a runner with the production deploy job.
- Pin third-party actions to a commit SHA rather than a moving tag.
Gotchas that break things
These are the problems I have actually hit or seen.
- Disk fills up. Workspaces,
node_modules, Docker layers and Playwright browsers accumulate. Add a weekly cleanup cron and an alert at 80 percent disk. - State leaks between jobs. A file left in the workspace by a previous run makes a broken build pass. Use
actions/checkoutwithclean: trueand avoid writing outside the workspace. - Environment differs from your shell. The service does not load your
.bashrc, sonodeorpm2may be missing fromPATH. SetPATHin the runner's.envfile or use absolute paths. - Runner version drift. Runners auto-update by default. If you disable that, you must update manually or GitHub will eventually refuse old versions.
- Registration tokens expire quickly. Script the setup so re-registering a runner after a rebuild takes minutes, not an afternoon.
- Long jobs and timeouts. Set
timeout-minuteson every job so a hung scraper does not occupy the runner forever.
How I built this in practice
On the Antoc side at Passdn Technologies, an automated SEO blog pipeline runs on a GitHub Actions self-hosted runner. It uses Groq-hosted LLaMA to generate content inside the workflow. An automated, long-running content job is exactly the workload where a self-hosted runner on our own GCP infrastructure makes more sense than a hosted one.
On X4ET, a B2B tech marketplace I built solo, I ran four GitHub Actions runners on AWS EC2 alongside Nginx and SSL, serving a Next.js frontend and a FastAPI backend. Multiple runners meant jobs did not queue behind each other, and labels kept every workflow pointed at the right runner.
Across GCP I also run self-hosted runners next to PM2, Nginx and systemd services. The pattern is the same each time: one dedicated user, labeled runners, concurrency groups on deploy jobs, and a cleanup cron.
Common mistakes
- Attaching a self-hosted runner to a public repository.
- Running the runner as root, or giving its user blanket sudo.
- Forgetting
concurrencyon deploy jobs, so overlapping deploys corrupt builds. - Never cleaning the work directory and running out of disk mid-deploy.
- Relying on interactive shell
PATHsettings that the service never loads. - Using one shared runner for every repo and trust level.
keep reading
FAQ
When should I use a GitHub Actions self hosted runner instead of GitHub-hosted?+
Use one when a job needs access to a private network, specific hardware, long runtimes, or a persistent environment such as the server you are deploying to. For ordinary tests on public infrastructure, GitHub-hosted runners are less maintenance.
Are self-hosted runners free?+
GitHub does not bill Actions minutes for self-hosted runners in the usual model, but you pay for the machine, its storage and your time to maintain it. Check GitHub's current pricing page because billing terms can change.
Is it safe to use a self-hosted runner on a public repo?+
GitHub recommends against it. Anyone who can open a pull request could potentially run code on the runner machine, so keep self-hosted runners on private repositories.
How many self-hosted runners can I run on one VM?+
Each runner processes one job at a time, so you can register several runners in separate directories on one VM to run jobs in parallel. Size CPU, memory and disk for the heaviest jobs running together.
Devang Gandhi
AI & full stack developer at Passdn, building CRMs, SaaS, AI agents and Flutter apps for clients in the US, UK, Australia, UAE and India. More about me