TL;DR: Two paths. For reads (clone, fetch, API reads), the sandbox's Git remote and API base URL point at a broker outside the sandbox, which checks the repository and operation against the session's policy and adds a short-lived, repository-scoped token. For writes, prefer that the sandbox never pushes: it produces a commit bundle or patch, and a trusted service outside checks it (allowed branch, no workflow-file changes, size limits) and pushes with its own credentials, then opens the pull request. Egress allows only the broker, and metadata endpoints are blocked.
How to approach it
Separate reading from writing, because their risks differ: a leaked read token exposes code; a write path can change what runs in CI. Then design each path, the policies, and the network rules that make the broker unavoidable.
A strong answer
Reads through a broker. Inside the sandbox, git remote is https://git-broker.internal/acme/payments.git and the API base URL is https://gh-broker.internal/. The broker, outside the sandbox:
- checks that the session may read
acme/payments(and nothing else); - obtains a short-lived installation token scoped to that repository (GitHub App installation tokens last about an hour and can be limited to selected repositories);
- forwards the request with the token and strips authentication from responses;
- logs the request with the session id.
Writes outside the sandbox. Letting the sandbox push, even through a broker, means generated code chooses what is pushed. The safer design:
- The agent commits inside the sandbox.
- The harness exports the commits as a bundle or patch.
- A trusted push service checks it, then pushes to a branch and opens a pull request with its own credentials.
BLOCKED_PATHS = (".github/workflows/", ".gitlab-ci.yml", "Dockerfile.ci")
def check_push(session, ref, changed_paths, deletes=False, size_kb=0):
problems = []
if not ref.startswith(f"refs/heads/agent/{session}/"):
problems.append(f"branch {ref} outside agent/{session}/")
if deletes:
problems.append("ref deletion not allowed")
for p in changed_paths:
if p.startswith(BLOCKED_PATHS):
problems.append(f"changes {p}, which runs with CI privileges")
if size_kb > 5_000:
problems.append("push larger than 5 MB")
return problems
ok = check_push("s42", "refs/heads/agent/s42/fix-rounding",
["src/billing/round.py", "tests/test_round.py"])
bad = check_push("s42", "refs/heads/main", [".github/workflows/deploy.yml"])
print(ok, len(bad)) # => [] 2
print(bad[0]) # => branch refs/heads/main outside agent/s42/
A change to CI workflow files is blocked because workflows run with credentials the agent should never influence; pushes to main are blocked because review happens through the pull request.
Network rules. The sandbox can reach the brokers and an internal package mirror, nothing else. Instance metadata is blocked. DNS resolves only allowed names.
Observability. Every broker request and every push decision is logged with session id and outcome, so an investigation can reconstruct what a session read and tried to write.
What interviewers probe next
"Developers want the agent to run git push naturally." A Git remote that points at the push service gives that experience: the push is received, checked and forwarded, or refused with a clear message, and the sandbox still holds no token.
"Private dependencies need registry tokens during install." Same pattern: the package mirror or registry proxy authenticates outside the sandbox.
"What if the agent needs to read a second repository?" The session's policy lists it explicitly; the broker refuses anything not listed, and the refusal tells the agent what was denied.
What if?
What if · interview follow-ups
Hold your answer as the constraints change
Reads go through a broker and writes through a trusted push service that checks each bundle.
Start here
What if generated code prints all environment variables to the logs?
What is there to print?
Nothing secret: no token was ever placed in the sandbox. The design makes this harmless rather than relying on the code not to do it.
Carry it forwardDesign so that exfiltration finds nothing.
Weak answerRedacting logs as the main control.
Constraint changes
What if the push adds a new workflow file under a different CI directory?
How complete is the blocklist?
Blocklists miss things. Combine them with branch protection and required reviews on the target repository, and have CI on agent branches run without secrets until a person approves.
Carry it forwardThe repository's own protections are the second line.
Weak answerRelying only on the path blocklist.
Constraint changes
What if the broker itself is compromised?
What does it hold?
Short-lived, narrowly scoped tokens, minted per session, which limits the damage. Run the broker with minimal privileges, separate from the sandboxes' hosts, and alert on unusual minting.
Carry it forwardKeep the broker's own access small and short-lived.
Weak answerA broker holding a long-lived organisation-wide token.
Now defend it
One-line design?
Reads through a broker that adds short-lived repository-scoped tokens outside the sandbox, writes as checked bundles pushed by a trusted service to agent branches with no CI-file changes, and egress limited to those services.
How it's scored
Weak: Puts a fine-grained token in the environment.
Hire: A broker or proxy that adds the token outside the sandbox, with scoped tokens.
Strong Hire: Separates read and write paths, uses short-lived repository-scoped tokens via a broker for reads, moves pushes to a trusted service that checks branch, deletions, CI files and size, forces egress through the brokers, blocks metadata, relies on branch protection as a second line, and logs every decision.
Common mistakes
- Any long-lived token inside the sandbox.
- Letting generated code push directly, even with a scoped token.
- Allowing changes to CI workflow files from agent branches.
- Leaving other egress open, so the broker can be bypassed.