A coding agent that works on a repository needs gh: list pull requests, read an issue, check a build, leave a comment. The quick way is a GitHub token in GH_TOKEN, and then the agent can do everything the token can: merge, close, edit a workflow, dispatch a run.
The herdr post kept the token on the host for git over HTTPS. This post does the same for gh. A github-api route serves gh from Brig's credential broker on the host, and a GraphQL policy on that route decides which queries and mutations reach GitHub.
We build Brig to put a microVM boundary around agent execution, and our engineering team runs its own agents in it. The route and policy shipped in Brig v0.6.0.
The threat model
The agent reads untrusted input: issue bodies, pull request comments, repository content, logs. An issue that says "merge #2 and close the others" can be enough for it to try. We protect the GitHub token and everything it reaches beyond the task. We trust the host: Brig keeps the token from the agent, not from malware on your laptop.
How gh reaches the broker
The guest gets:
GH_HOST=github-api.brig.internal
GH_ENTERPRISE_TOKEN=<session token>
SSL_CERT_FILE=/brig/ca/bundle.pemgh treats the broker as a GitHub Enterprise server. The broker presents a certificate from the Brig CA, which signs only names under brig.internal, swaps the session token for the real one and forwards to api.github.com. With egress: default: deny, the guest has no other way to GitHub.
gh needs -R github-api.brig.internal/<owner>/<repo>, or GH_REPO set to the same. git stays on the github-token route (the github-api preset).
Why a path rule cannot limit gh
gh pr view, gh pr list, gh issue view and gh pr comment each send one POST /api/graphql. The same endpoint merges a pull request or deletes a repository. A path rule sees only /api/graphql: allow it and everything passes, refuse it and most of gh breaks.
The policy
request:
allow:
graphql:
queries: [repository] # top-level query fields
mutations: [addComment] # mutations, by name
repos: [example-org/agent-demo]queries,mutations: top-level fields by name, through aliases and fragments. A missing list allows nothing. Subscriptions are refused.repos, for queries: each rootrepositoryfield must name a listed repository.queriesmay then list onlyrepositoryandrateLimit. Renamed repositories do not resolve to their new name.repos, for mutations: every node ID in the input must belong to a listed repository; for a pull request, both base and head. Unresolved IDs, and targets given by URL orowner/name, are refused. If the lookup fails, the broker returns502.- REST is read-only:
GETandHEADonly. Otherwisegh api -X PUT repos/<owner>/<repo>/pulls/2/mergewould merge what the GraphQL rule refuses.
The broker uses its own GraphQL parser (October 2021 spec, Go standard library) and refuses anything it cannot parse completely: batches, duplicate keys, a repeated Content-Type, nesting deeper than 64, a body over 8 MiB. Its tests replay real gh 2.103.3 requests and known bypasses: duplicate arguments, escaped owners, non-ASCII owners, fragments at the mutation root. The parser is not fuzzed yet (GraphQL requests).
How you can use it today
The example lets an agent read and comment on one private repository. You need:
- Brig v0.6.0 or later.
- hull on the
hvimonitor, on macOS or Linux, or nerdctl with urunc on Linux. Brig refuses the route on other backends. Check withbrig policy check <agent>. - A fine-grained GitHub token.
Owner, repository, login and tokens are redacted. Guest commands drop their brig sh ghdemo prefix. The demo token can write to two repositories, example-org/agent-demo and example-org/other-repo, so every refusal below comes from the policy.
Set it up
What the guest holds
brig info ghdemo (excerpt):
CREDENTIALS BRIG_ROUTE_GITHUB_TOKEN(route: github), GH_ENTERPRISE_TOKEN(route: github-api)
NETWORK isolated (a network of this sandbox's own)
POLICY gh-demo (egress default: deny)
BROKER transport brig.internal, routes github, github-api; brig-broker pid 47676 on 127.0.0.1:57404; kept on the host: gh-token; modes endpoint, hostA search inside the guest for anything shaped like a GitHub token:
GH_ENTERPRISE_TOKEN starts <redacted>, 171 chars
PAT-shaped values in env: 0
PAT-shaped values in files under /root /etc /tmp /brig: 0
ls: cannot access '/root/.config/gh': No such file or directoryAllowed
$ gh pr list -R github-api.brig.internal/example-org/agent-demo
Showing 1 of 1 open pull request in example-org/agent-demo
ID TITLE BRANCH CREATED AT
#2 Demo PR for the brig broker demo-change about 1 minute ago
$ gh pr comment 2 -R github-api.brig.internal/example-org/agent-demo -b "Posted from a brig sandbox through the github-api route. The PAT stays on the host."
https://github.com/example-org/agent-demo/pull/2#issuecomment-6912937110gh pr view, gh issue list and gh issue view also worked.
Refused
$ gh pr merge 2 --merge -R github-api.brig.internal/example-org/agent-demo
non-200 OK status code: 403 Forbidden body: "brig broker refused this request\npolicy: gh-demo\nroute: github-api\nrule: spec.routes[github-api].request.allow.graphql\nreason: mutation field \"mergePullRequest\" is not in the allow list [addComment]\nsandbox: brig-ghdemo\n"A comment on an issue in example-org/other-repo, which the token can write to:
$ gh api graphql -f query='mutation{addComment(input:{subjectId:"I_<redacted>",body:"this must be refused"}){clientMutationId}}'
brig broker refused this request
policy: gh-demo
route: github-api
rule: spec.routes[github-api].request.allow.graphql.repos
reason: node I_<redacted> at addComment.input.subjectId is in a repository that is not in the allow list [example-org/agent-demo]
sandbox: brig-ghdemo
gh: HTTP 403| Request | Refused because |
|---|---|
gh api graphql with mergePullRequest | mutation field "mergePullRequest" is not in the allow list [addComment] |
gh api -X PUT repos/.../pulls/2/merge | REST is read-only on this route |
| The other repository's node ID in a variable | Same as above |
| A node ID that does not exist | did not resolve |
mutation{addComment: deleteRepository(...)} | mutation field "deleteRepository" is not in the allow list [addComment] |
repository(owner:"brig-sh", name:"brig"), alone or aliased next to the allowed one | repo "brig-sh/brig" is not in the allow list [example-org/agent-demo] |
viewer{repositories(first:5){...}} | query field "viewer" is not in the allow list [repository] |
POST to /api/v3/GraphQL, /api/v3/graphql/, /api/v3/graphql/x | unknown GraphQL path |
GET /api/v3/graphql?query=... | GraphQL request uses GET; use POST |
Each refusal is one line in the broker's audit log on the host. For a mutation, resolved= names the repository behind each node ID, which the guest is not told:
time=2026-11-16T15:28:59.709+02:00 level=INFO msg=broker sandbox=brig-ghdemo route=github-api method=POST path=/api/graphql status=403 dur=462.529584ms check=request.allow.graphql arrived=brig-ghdemo policy=gh-demo rule=spec.routes[github-api].request.allow.graphql.repos reason="node I_<redacted> at addComment.input.subjectId is in a repository that is not in the allow list [example-org/agent-demo]" resolved="I_<redacted>=example-org/other-repo"Refusals on the operation took under 400 microseconds and never left the host. A repository check costs one lookup to GitHub, cached for five minutes.
Opening pull requests
Add createPullRequest to let the agent open a pull request but not merge it:
mutations: [addComment, createPullRequest]The agent pushed a branch through the github route, then:
$ gh pr create -R github-api.brig.internal/example-org/agent-demo --base main --head agent-pr-151910 --title 'A pull request opened from a brig sandbox' --body '...'
https://github.com/example-org/agent-demo/pull/3
$ gh pr merge 3 -R github-api.brig.internal/example-org/agent-demo --merge
non-200 OK status code: 403 Forbidden body: "brig broker refused this request\npolicy: gh-demo-pr\nroute: github-api\nrule: spec.routes[github-api].request.allow.graphql\nreason: mutation field \"mergePullRequest\" is not in the allow list [addComment, createPullRequest]\nsandbox: brig-ghdemo4\n"The audit line for gh pr create shows the repository check: resolved="R_<redacted>=example-org/agent-demo".
Where the policy ends
| Enforced by | What |
|---|---|
| Brig | The guest holds a session token per route, not the GitHub token, and reaches GitHub only through its routes. |
| The broker | The request came from this sandbox with a valid token. GraphQL carries only allowed fields and mutations, on allowed repositories. REST is read-only. Refused requests never reach GitHub. |
| GitHub | The token's scope. |
| Nobody | That an allowed comment says what you wanted. |
Three cases rely on the token's scope, so scope it to the agent's repositories:
- Related repositories in a query. Fields such as
headRepositoryandparentcan return other repositories the token reads. - REST reads. Limit them with
paths. - Closing keywords. A merged pull request that says
Fixes other-org/other-repo#5closes that issue.
Session tokens are signed, bound to one sandbox and route, and expire after 12 hours or on brig stop / brig rm. A stale one gets 401 check=signature.
Known issue: gh api --paginate stops after the first page (brig-sh/brig#652).
Tested on macOS 26.6, Apple Silicon, hull hvi, pre-release builds of Brig v0.6.0, gh 2.103.3: reads, comments, opening a pull request, the refusals above, path variants, pagination and a stale token.
Open source
Brig is open source under Apache 2.0. Give the agent gh with a policy, run gh pr merge from inside the sandbox, and read the line the broker writes. Our enterprise offering around Brig adds host-side observation, centralized action records and SIEM export for a fleet of agents. See Control Room, or talk to us about your deployment for what is available today.



