# Is it safe to use self-hosted runners on a public repository?

Generally no: GitHub says self-hosted runners should almost never be used for public repositories. The attack path with sources, what each defence changes, and what to run instead.

By Grant Unwin, published 2026-11-01. Checked against GitHub's documentation on 2026-11-17. The web page: https://www.runners.io/blog/are-self-hosted-runners-safe-on-a-public-repository

Generally no. GitHub’s own guidance is that self-hosted runners should almost never be used for public repositories, because any user can open a pull request against the repository and compromise the environment, including its secrets and the `GITHUB_TOKEN`. A 2023 write-up showed it working against GitHub’s own repository. The simplest safe answer is to run pull requests from a public repository on GitHub-hosted runners. Our [GitHub self-hosted runner](https://www.runners.io/blog/self-hosted-github-actions-runner-cost) guide counts the full cost.

**In short**

- GitHub says self-hosted runners should almost never be used for public repositories, because any user can open a pull request.
- A 2023 write-up used a fork pull request and non-ephemeral runners in GitHub's own runner-images repository.
- By default only first-time contributors need approval, so a merged typo fix can skip the gate.
- Ephemeral runners remove the persistence step; they do not remove the attacker's job or its secrets.
- The simplest safe answer is GitHub-hosted runners for pull requests from a public repository.

This page is the attack path with its sources, what each defence does and does not change, and where ephemeral runners fit. It is security and trade-offs only. Every GitHub statement was read from GitHub’s pages on the date this post was last checked, and the incident from the researcher’s own write-up and the press coverage of it.

## How does an attack on a self-hosted runner in a public repository work?

In 6 steps, each with its source. The case is the one researcher Adnan Khan published on 20 December 2023, about GitHub’s own `actions/runner-images` repository, which used non-ephemeral self-hosted runners and the default approval setting.

| Step | What happens | Source |
| --- | --- | --- |
| 1. A fork pull request starts a workflow | On GitHub's account, anyone who can fork the repository and open a pull request can compromise a self-hosted runner and gain access to its secrets and the GITHUB\_TOKEN. | GitHub, secure use |
| 2. The approval gate is passed | By default, all first-time contributors require approval to run workflows. With either of the first two options, a user who has had any commit or pull request merged does not need approval. In 2023 a one-character typo fix, merged on 20 July, made a researcher's later runs skip it. | GitHub, Actions settings; the 2023 write-up |
| 3. The workflow asks for the runner | A fork pull request's workflow is read from its merge commit, so its author can change runs-on to the self-hosted labels. | The 2023 write-up |
| 4. The runner is persistent | The runner was non-ephemeral, so the agent the researcher's payload installed kept running after the job ended. It registered another runner agent to a repository the researcher controlled, and access persisted from 21 to 26 July 2023. | The 2023 write-up |
| 5. The secrets and the token are within reach | The write-up reached a GITHUB\_TOKEN with write permission, read from .git/config because checkout persists credentials by default, and build secrets including credentials for an internal virtual machine manager. | The 2023 write-up |
| 6. The outcome | Reported to GitHub through HackerOne on 22 July 2023, resolved and rewarded on 14 November 2023. The same method, in a later report, gave the researchers persistent access and could have let an attacker upload malicious PyTorch releases; Meta considered it mitigated. | The 2023 write-up; SecurityWeek, 12 January 2024 |

The same method reached PyTorch. SecurityWeek reported on 12 January 2024 that the researchers extracted secrets, including AWS keys and GitHub personal access tokens, and that the tokens had access to over 93 repositories in PyTorch’s organization. Meta told them the issue was considered mitigated. The coverage describes a malicious PyTorch release that could have happened, not one that did, and describes the method as working against repositories that have self-hosted runners attached, where a pull request can make an outsider a contributor who then runs workflows without approval.

## What does each defence change?

| Defence | What it changes | What it does not |
| --- | --- | --- |
| Use GitHub-hosted runners for pull requests | GitHub says its hosted runners execute code in ephemeral and clean isolated virtual machines, with no way to persistently compromise the environment. | Standard GitHub-hosted runners are free for public repositories, and larger runners are billed per minute. A job that needs your network or hardware cannot use either. |
| Ephemeral or just-in-time runners | A runner takes at most 1 job and is removed, so a compromised runner registration does not persist. | GitHub says re-using hardware to host just-in-time runners can risk exposing information from the environment, so the machine has to be clean too. |
| Require approval for all external contributors | Removes the loophole of a merged typo fix. The 2023 write-up calls it the easiest mitigation. | A maintainer can still be tricked into approving a pull request, so it is a gate and not a boundary. |
| Runner groups limited to named repositories | By default only private repositories can access runners in a runner group; keep it that way. | It stops a public repository reaching the runner. It does nothing for a private one that accepts forks. |
| A condition in the workflow file | Nothing, for a pull\_request trigger: the workflow file comes from the merge commit, so the author can remove the condition. | Do not rely on an if: condition to keep a fork off a runner. |

The last row is the one that surprises people. A condition in a workflow file cannot keep a fork off a runner, because for a fork pull request on the pull\_request trigger the workflow that runs is the one in the merge commit, and the author controls it. Put the control where the author cannot reach it: in which runners the repository may use at all, and in the approval setting.

## Do ephemeral runners make it safe?

They make it much smaller, not safe. An ephemeral runner removes the persistence step of the attack, and GitHub and the press coverage of it both point to them. But the job still runs the attacker’s code with the secrets and the token it was given, for as long as it runs, and GitHub says re-using hardware to host just-in-time runners can risk exposing information from the environment. What an ephemeral runner is, and how it differs from a just-in-time one, is in [What is an ephemeral runner?](https://www.runners.io/blog/what-is-an-ephemeral-github-actions-runner)

## What should a public repository run on?

GitHub-hosted runners, with a read-only token and no credentials left in the checkout. For a public repository that is a workflow like this, whose pull request code never reaches a machine you keep:

```yaml
name: ci
on:
  pull_request:
  push:
    branches: [main]
permissions:
  contents: read
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          persist-credentials: false
      - run: make test
```

The sample uses the movable tag `v7` so that it reads clearly. Pin the actions and lock the dependencies as well; the [security hardening post](https://www.runners.io/blog/github-actions-security-hardening) and the [lockfile explainer](https://www.runners.io/blog/github-actions-lockfile) are the checklist. GitHub also says to be cautious with self-hosted runners on private and internal repositories, since anyone who can fork the repository and open a pull request, generally those with read access, can compromise the runner.

## How do our runners handle a fork’s pull request?

Each job runs in its own virtual machine, which no other job uses and which is destroyed, or rebuilt from the image, when the job ends, so nothing a fork’s build leaves on its machine reaches another job, apart from the caches you keep on purpose. A build whose workflow run comes from a fork is not given a sticky disk, and nothing it writes is ever kept. Our documentation is plain about the remaining edge: GitHub hands a runner whichever queued job of your repository matches its label, so a fork’s build can land on a runner we prepared for a trusted build, and then it can read that runner’s copy of the disk. If you have sticky disks on, protecting the repository, which is off by default and set per repository, closes that. A fork’s build you approve still runs with the secrets GitHub hands its runner, on a machine we operate. The [sticky disk protection page](https://www.runners.io/docs/caching/sticky-disk-protection) and the [security documentation](https://www.runners.io/docs/runners/security) have the whole of it, and [what to ask any runner service](https://www.runners.io/blog/is-a-third-party-github-actions-runner-service-safe) is the checklist to hold us to it. Our [self-hosted runner alternative](https://www.runners.io/compare/self-hosted-github-runners) page sets out the other way: the same runs-on line, and no machines of your own to patch or scale.

## Sources

- [Secure use reference](https://docs.github.com/en/actions/reference/security/secure-use)
- [GitHub-hosted runners reference](https://docs.github.com/en/actions/reference/runners/github-hosted-runners)
- [Managing GitHub Actions settings for a repository](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository)
- [Managing access to self-hosted runners using groups](https://docs.github.com/en/actions/how-tos/manage-runners/self-hosted-runners/manage-access)
- [One supply chain attack to rule them all (Adnan Khan, 20 December 2023)](https://adnanthekhan.com/2023/12/20/one-supply-chain-attack-to-rule-them-all/)
- [New class of CI/CD attacks could have led to PyTorch supply chain compromise (SecurityWeek, 12 January 2024)](https://www.securityweek.com/new-class-of-ci-cd-attacks-could-have-led-to-pytorch-supply-chain-compromise/)
- [Security (runners.io documentation)](https://www.runners.io/docs/runners/security)

## Frequently asked questions

### Is it safe to use self-hosted runners on a public repository?

Generally no. GitHub's guidance is that self-hosted runners should almost never be used for public repositories, because any user can open a pull request against the repository and compromise the environment, including its secrets and the GITHUB\_TOKEN. Use GitHub-hosted runners for pull requests.

### How can a fork pull request attack a self-hosted runner?

A fork's workflow runs from its merge commit, so its author can set runs-on to your self-hosted labels. Under GitHub's default approval setting, one merged contribution means that user's later pull requests need no approval, and a persistent runner keeps whatever the job leaves behind. A 2023 write-up did this to GitHub's own runner-images repository.

### Do ephemeral runners make self-hosted runners safe on a public repository?

They make it much smaller, not safe. An ephemeral runner removes persistence, but the attacker's job still runs with the secrets and token it was given, and GitHub says re-using hardware for just-in-time runners can risk exposing information. Require approval for all external contributors too.

### Can I use self-hosted runners on a private repository?

GitHub says to be cautious there too, because anyone who can fork the repository and open a pull request, generally those with read access, can compromise the runner. GitHub recommends self-hosted runners only for private repositories, and by default only private repositories can access runners in a runner group.
