Use case

Turn an issue into a pull request.

Label an issue and walk away. An agent picks it up on a machine of its own, makes the change, runs the tests and opens a pull request for you to review.

The problem

Small issues pile up because each one costs a person a context switch: check out the code, find the spot, fix it, run the tests, open the pull request.

An agent can do all of that, if something tells it the issue exists and it has somewhere to do the work with a token for your repository.

How Annex does it

  1. Give the task a web address

    Annex gives a task an address GitHub can call. Point your repository's issue events at it. Calls wait safely until a sandbox takes them, even if none is running yet.

  2. The agent takes the issue

    Each call lands in the sandbox with the issue in it. The agent clones the repository using a GitHub token from your secrets, which it can use and never sees printed.

  3. It opens the pull request

    It makes the change, runs the tests, pushes a branch and opens the pull request. You review it like anyone else's.

What it looks like

Make the address, and say what to run for each call.

Inside a sandbox

curl -X POST "$ANNEX_URL/v1/workspaces/$ANNEX_WORKSPACE_ID/tasks/$ANNEX_TASK_ID/webhooks" \
  -H "Authorization: Bearer $ANNEX_TASK_TOKEN" \
  -d '{"name": "github", "command": "./fix-issue.sh"}'

Walkthrough

Build it yourself, part by part.

Label an issue and walk away. A sandbox starts, an agent clones the repository there, finds the bug, fixes it, runs the tests and opens a pull request. You come back to a diff to review.

The agent in this example is Claude Code, but the pattern is the same for any of them. What matters is where it runs and what it is allowed to hold, so most of this walkthrough is about that.

agentAn issuelabelledclonefixrun the testspushA sandboxthe agent works hereA pull requestfor you to review

The whole thing is about 70 lines. Get the code →

  1. A machine with the agent's tools on it

    The agent needs git, the GitHub command and itself. Those go in a template, with one more line that matters: a secret group.

    The GitHub token and the model's key are kept by Annex and put into the sandbox's environment when it starts. The small server that listens for GitHub never holds either of them.

    annex.yml

    name: issue-to-pr
    description: git, the GitHub CLI and Claude Code
    vcpu: 2
    memory_gib: 4
    route: cheapest
    secret_groups: [issue-to-pr]   # GH_TOKEN and ANTHROPIC_API_KEY, kept by Annex (dashboard, Secrets)
    setup:
      - |
        S=; [ "$(id -u)" = 0 ] || S=sudo
        $S apt-get update && $S apt-get install -y git gh nodejs npm
      - |
        S=; [ "$(id -u)" = 0 ] || S=sudo
        $S npm install -g @anthropic-ai/claude-code
  2. Believe only GitHub

    GitHub tells your server when an issue is labelled. Anyone on the internet can send the same message, so the server checks the signature GitHub puts on each one before reading a word of it.

    server.mjs

    const want = Buffer.from('sha256=' + createHmac('sha256', SECRET).update(body).digest('hex'))
    const got = Buffer.from(req.headers['x-hub-signature-256'] || '')
    if (got.length !== want.length || !timingSafeEqual(got, want)) return res.writeHead(401).end()
  3. The work is a short script

    What runs in the sandbox is eight lines of shell: clone, make a branch, let the agent work, commit, push, open the pull request.

    Look at how the issue gets there. Its text is a file and its title an environment variable; neither is ever part of a command. An issue is text a stranger wrote, and text pasted into a command line is a command.

    server.mjs

    const WORK = `set -e
    git clone --depth 50 "https://x-access-token:$GH_TOKEN@github.com/$REPO.git" /tmp/repo
    cd /tmp/repo
    git checkout -b "$BRANCH"
    IS_SANDBOX=1 claude -p "$(cat /tmp/issue.md)" --dangerously-skip-permissions
    git add -A
    git -c user.name="issue-to-pr" -c user.email="issue-to-pr@users.noreply.github.com" commit -m "Fix #$NUMBER: $TITLE"
    git push origin "$BRANCH"
    gh pr create --repo "$REPO" --head "$BRANCH" --title "$TITLE" --body "Closes #$NUMBER. Written by an agent: read it before merging."`
  4. Start, run, always stop

    The server starts a sandbox for the issue, uploads the issue's text, runs the script and stops the sandbox whether it worked or not. A lifetime of two hours is a second guard against one that runs away.

    server.mjs

    const sb = await annex.start({ template: 'issue-to-pr', lifetime_minutes: 120 })
    try {
      await annex.ready(sb.id)
      await annex.upload(sb.id, '/tmp/issue.md', prompt)          // the issue, as a file
      await annex.run(sb.id, WORK, {
        timeout: 3600,
        env: { REPO: repo, NUMBER: String(issue.number), BRANCH: `agent/issue-${issue.number}`, TITLE: issue.title },
      })
    } finally {
      await annex.stop(sb.id)                                     // whatever happened
    }

Before you rely on it

  • The agent reads text a stranger can write while holding a token. The sandbox keeps a misled agent away from your computer, not away from the repository: use a token limited to that one repository, and label only issues you have read.
  • Nothing here merges. Every pull request waits for a person.
  • A long job is safer with checkpoints on, so a machine that is lost mid-way costs minutes, not the whole run.

Get the code on GitHub

Related use cases