Security and AI
Sandboxing an AI security reviewer before it reviews anything
We piloted AI agents that look for vulnerabilities in pull requests. Before trusting them with real code, I tested whether their own permission rules actually held. Some didn’t.
- Stack
- GitHub Actions reusable workflows, Docker, an agentic coding CLI running Claude models, S3
- My role
- Permission testing, sandbox design and the pipeline
- Outcome
- A reusable PR security check that runs in an isolated, pinned runtime, with an opt-in gate that can block merges.
The design
The check uses two agents. A hunter reads the diff and the code around it, then proposes findings. A validator tries to confirm each one, and builds a proof of concept for any it confirms. The report goes on the pull request and is archived in S3. Teams choose whether to let it block merges.
The threat model problem
A security reviewer reads untrusted code, including comments and strings an attacker controls. If a prompt injection takes over an agent that has write access, it could edit the workflow’s own scripts and report the pull request as clean. That makes the agent’s tool permissions the security boundary. So I tested them before relying on them.
What testing showed
- File-write rules weren’t enforced. The allow and deny rules for file writes in the agent’s config had no effect in non-interactive mode with tools trusted. The hunter could write inside the repo and outside it.
- Shell rules were enforced, with a gap.
git diff --output=<path>writes a file, which got around them. I fixed it by denying--output,--ext-diff,--no-indexandgit -c, and denying anything not explicitly allowed. - Repo-defined agents loaded without a trust prompt in non-interactive mode.
So the boundary moved to the container
Config rules are useful, but they aren’t enforcement. The workflow now runs each agent in a throwaway container:
- The base image is pinned by digest, and the agent CLI is pinned by sha256.
- Proofs of concept run with no network.
- Anything the agent writes lands inside a disposable container, not on the runner or in the action’s own scripts.
- The model API key comes from an organization secret, not from the repo.
The report also includes the hunter’s leads that the validator couldn’t confirm. People can see what was considered and dropped, not only what was confirmed.
Proving it end to end
Before marking it ready, I ran the full pipeline on a small repo with a planted bug. The hunter found it, the validator confirmed it, the proof of concept worked, and the gate failed the check, as it should. It’s piloting on one repository. Other repositories can call it with one line.
What the sandbox doesn’t cover yet
- A hijacked agent can still lie. The container stops it from rewriting scripts, but not from calling a real bug clean. The gate should read structured findings, and the validator should check the code without seeing the hunter’s conclusions.
- The container has network access and the model API key. An egress allowlist that permits only the model API, plus a short-lived key scoped to the job, would close the path to sending the key out.
- Agent definitions should come from the action, never the pull request. Loading them from the action’s own pinned copy removes the trust-prompt gap.
What I took from it
- Test a guardrail before relying on it. Documentation tells you what was intended, not what happens.
- For agents that read untrusted input, enforce limits at the OS and container layer, not in the prompt or config.
- Pin everything an automated security check runs. Otherwise the check is itself part of your attack surface.