# The GitHub Actions job that runs my coding agent cannot write to the repo

> Source: <https://dev.to/alphacrack/the-github-actions-job-that-runs-my-coding-agent-cannot-write-to-the-repo-57m7>
> Published: 2026-12-04 20:56:29+00:00

**Recommendation:** Give agent jobs read-only tokens with no persisted credentials, and put all writes in a separate workflow_run publisher that never executes agent artifacts.
More in the playbook "Securing agents and AI tools": <https://wpnews.pro/playbooks/agent-security>

I wanted a pipeline where I label a GitHub issue and come back to a pull request. Label `agent:spec`, and a coding agent writes a proposal. Read it, label `agent:build`, and the agent writes the code. My laptop can be closed the whole time.

The agent part was the easy bit. The hard question was: **what is the job that runs the agent allowed to do?**

Because whatever the job can do, the agent can be talked into doing. The issue text is input. Comments are input. A test file in the repo is input. Any of it can say "ignore your instructions and push this to main".

The obvious version is one workflow: check out the repo, run the agent, then `git push` and `gh pr create` with a token that can write. It works on the first try. It also means the agent runs on a machine where a write token sits in the environment, in `.git/config`, or one `env` away.

Every workflow that runs an agent starts with no permissions and adds back only reading:

```
permissions: {}

jobs:
  agent:
    permissions:
      contents: read
      issues: read
    steps:
      - uses: actions/checkout@v4
        with:
          persist-credentials: false   # no token in .git/config
```

The agent can read the code and the issue. It cannot push, comment, label or open a pull request, whatever the issue text says.

A read-only `GITHUB_TOKEN` is not enough on its own. To open a pull request that triggers CI, you need a personal access token, and that is a secret.

The detail that shaped the whole design: GitHub hands a runner the secrets that its **workflow file** mentions. So a write secret in another job of the same file is still too close. The write step lives in its own file, `agent-publish.yml`, and the agent workflows never name a secret that can write.

`agent-publish.yml` starts on `workflow_run`, when an agent workflow finishes. It always runs the default branch's copy of itself, so a branch cannot change what publishing does.

```
on:
  workflow_run:
    workflows: ["Agent · spec", "Agent · build", "Agent · CI triage"]
    types: [completed]
```

It downloads the agent run's artifact: a `result.json`, the files of one proposal, or a git bundle of commits. It reads those as data, cuts them to size, and executes nothing from them. A build only adds commits, never rebases or force-pushes, and may not touch the pipeline's own files.

Which issue the run belongs to does not come from the artifact either. It comes from the run's title, which GitHub sets from the agent workflow's `run-name` before any agent starts:

```
run-name: "${{ github.event.label.name == 'agent:spec' && format('agent:spec #{0}', github.event.issue.number) || 'skipped (another label)' }}"
```

So an agent cannot make the publisher write to a different issue.

Only people with triage access can add a label. So the label is the approval of the issue **as it was at that moment**. The agent gets that snapshot from the event, without HTML comments (an easy place to hide instructions), and comments from people who are not maintainers are dropped.

One more case: an issue template can apply a label for whoever opens the issue. A label that arrived that way from an outsider is not an approval, and starts nothing.

I ran the pipeline against a scratch issue for days before launch. Things that broke, in order:

`bubblewrap` and `socat` on the runner, and a sysctl on Ubuntu 24.04. Without them, no shell command starts.`.git/config` read-only by design, so the agent cannot commit. The workflow now commits for it, after checking that no credential is in the output.
Each of those was a small fix. None of them weakened a rule above.

I would rather say this than have someone find it:

`sudo`. The sandbox raises the bar; it is not a wall.
All of this is in the project's SECURITY.md, with the threat model.

The pipeline is part of [devtoli](https://github.com/alphacrack/devtoli), an open-source (MIT) cockpit I built to run coding agents across my ~40 repos. The workflows are in `templates/repo/.github/workflows/`, and tests pin each guard so a later change cannot quietly drop one.

If you see a hole, I would like to hear it. One stranger already opened an issue with six review points in the first week, and the fix is merged.
