# Containing an AI coding agent with two GitHub Actions jobs

> How Smi turns a ticket into a draft PR while the AI agent only holds a read-only token, what was verified on real runs, and what isn't wired yet.

Source: https://ebrahimsameh.com/blog/agent-in-a-box-smi/
Updated: 2026-11-20

You can let an AI coding agent work on a repository without ever giving it a token that can push. Smi does it with two GitHub Actions jobs. An `agent` job runs the model with read-only permissions and produces a patch. A separate `ship` job, which the agent can't reach, applies the patch and opens a draft pull request. The agent's limits are its token scopes, so none of the guarantees depend on the model following instructions.

## Why not just tell the agent to open drafts?

Because a prompt is input to the model. A line that says "only open draft PRs" is a request, and two things can break it: the model can ignore it, and the issue the agent is working from can contain text that talks it out of it. Anyone who can file an issue can write that text.

So in Smi the rules live in places the model can't edit. They're in the job permissions, in a workflow file the agent can't change, and in a shell script that checks the patch.

## How the two jobs split the credentials

| Job | Credentials | What it does |
| --- | --- | --- |
| `agent` | `contents: read`, only so checkout works on a private repo | Runs the model and writes a patch |
| `ship` | `contents: write`, `pull-requests: write` | Applies the patch and opens a draft PR |

The `agent` job can read the code and nothing else. It can't push a branch, open a pull request or mark anything ready for review, because its token doesn't have those scopes. Whatever the model decides to try, GitHub refuses it.

The `ship` job has write access, but it doesn't run the model. It takes the patch as data, checks it, applies it and opens the PR. `--draft` is a literal in that job, and there's deliberately no config key that changes it.

The patch is checked twice by `bin/guard.sh`: once in the `agent` job for fast feedback, and again in the `ship` job, which is the check that counts. The guard refuses anything under `.github/**`, with no exceptions. An agent that can edit CI can merge its own code.

## What was verified on real runs

The core works end to end on a private testbed: a GitHub issue labelled `smi` becomes a draft pull request. These assertions were checked on real runs:

| Assertion | Result |
| --- | --- |
| PR is opened as a draft | `isDraft=true` |
| Agent-permission token cannot push | `403 Write access to repository not granted` |
| Agent-permission token cannot open a PR | refused |
| An unlabelled issue is ignored | `ship=skipped`, no spend |
| A retry does not open a second PR | `ship=skipped` via branch dedupe |
| Two events 1s apart (`opened` + `labeled`) | exactly one PR |
| CI on a `GITHUB_TOKEN` PR | `action_required`: created but blocked |

The negative rows matter most. A containment model is only real if you keep testing that the forbidden things fail, so `templates/smi-assert.yml` ships those checks as a `workflow_dispatch` regression test. If it ever passes its negative assertions, the security model is decoration.

## What isn't wired yet

- Linear and Better Stack ingress are designed but not wired. Today the only entry point is a labelled GitHub issue.
- CI on a pull request opened with `GITHUB_TOKEN` shows `action_required`. The PR is created, but its checks are blocked. That's the last row in the table and it's a known gap.
- Install currently vendors the toolkit into `.smi/` and needs access to the private source. Once the repo is public, install becomes a single `uses:` line pointing at the shared workflow, and `.smi/` goes away.
- The source is private for now.

## Should you use it instead of Copilot?

If you already pay for GitHub Copilot, probably not. Copilot's coding agent has Linear and Slack entry points and a platform-level guarantee that its PRs stay drafts, which Smi can only approximate. Smi exists for the two things Copilot's agent doesn't do: it has no alerting integration (no Sentry, Better Stack, PagerDuty or webhook), and its automation config is private to whoever created it and never enters Git. With Smi, the workflow and its config are files in your repo, running on your Actions minutes and your own API key.

More on the design is on the [Smi project page](/projects/smi/).
