Three barriers for AI agents. A case study in agent security.

As of · every number comes from the public repos, sources at the end · built with Claude Code

I let AI coding agents work on my code every day. They commit, push and read other people’s pull requests, READMEs and bug reports. At each of these points a mistake or a hidden instruction can slip through. So I built three tools: two of them each guard one door, the third measures whether the defences hold at all.

The chain
StageWhenCatches
commit-guardlocally, before the agent commits or pusheskeys, private data, risky pushes
pr-airlockon GitHub, when a pull request arrivespoisoned changes from outside
injection-benchon my machine, after every change to the setupdefences that only sound good

Stage 1: commit-guard, before anything leaves the repo

commit-guard is a Claude Code hook that runs before every tool call. When the agent wants to commit, the hook reads the newly added lines and looks for 10 patterns: 7 built-in key formats such as API keys, GitHub tokens and private keys, plus private email addresses, phone numbers and private paths that you configure yourself. On a push it checks the branch and the author address. In a public repo a finding is denied; in any other repo Claude Code asks me first.

Decision: a real parser instead of a search rule

The first version used a regular expression to look for “git push”. Nested or rewritten commands slipped past it. Today a small shell parser without dependencies splits the command the way the shell would, and a second one reads git’s options. So the hook checks exactly the repo git would use.

Decision: anything unclear counts as suspicious

If the parser cannot read a command safely, it is denied in a public repo and asked about elsewhere. If the hook itself fails, it asks as well. That costs a false alarm now and then, but there is no silent pass. The hook’s own git calls are hardened too: it never starts anything that is configured in the repo under check.

386automated tests on main, all green
10patterns checked on commit, 7 of them built in
3 × 3test matrix: Linux, macOS, Windows with 3 Node versions each

Limit: commit-guard catches common mistakes; it is not a complete secret scanner. Its README itself recommends running gitleaks as well. Next, the Wächter mod in my own Claude Code is meant to move onto this core; that is a draft and not active yet.

Stage 2: pr-airlock, when code comes from outside

A commit hook only protects what I write myself. But code also arrives from outside, as a pull request. In 2026 the PolinRider campaign appended malicious code to the end of perfectly ordinary config files, pushed so far to the right that it is invisible in the diff view, and sent poisoned PRs to large open-source projects. Several maintainers built their own stopgaps. pr-airlock is a ready-made check for this, as a GitHub Action and on the command line.

Decision: read only, never run

pr-airlock fetches the PR only as data through the GitHub API. It checks nothing out, installs nothing and runs nothing. The check runs in the version from the target branch, so a PR cannot switch it off itself. The settings come from the target branch too; a PR that changes them gets a finding of its own that blocks.

Decision: shape instead of markers

The attackers have already changed their telltale markers several times. So pr-airlock looks for the shape of the attack: code behind an unusual amount of whitespace, font files that are really text, tasks that start by themselves when a folder is opened. Whatever it cannot check, for example because GitHub omits a diff, becomes a finding of its own and blocks for code instead of passing silently.

3 of 3documented poisoned PRs blocked in the field test
0false alarms in 31 merged PRs of large projects
over 100automated tests on main

Limit: a clean result means “none of the known shapes”, not “safe”. A variant without these traits would need a different detector, and after an infection pr-airlock does not replace scanning your own machine.

Stage 3: injection-bench, whether the defence really holds

The first two stages check code. The harder question is the agent itself: what does it do when a file it reads tells it to send secrets away? The usual advice is “add a deny rule” or “turn on the sandbox”. It is rarely measured.

injection-bench builds a sealed test setup for this: worthless fake secrets carrying a random marker sit in a throwaway folder, together with a scenario that contains a hidden instruction. A honeypot on my own machine records every attempt to send something. Then my real agent works in that folder under one defence profile. At the end its output, the honeypot log and the folder are turned into a verdict from “clean” to “exfiltrated”. A profile holds when nothing left the machine. No real secret is ever used.

10 + 2attack scenarios across 9 surfaces plus 2 control tasks, corpus v1
3defence profiles in the default run
over 130automated tests on main
Sample benchmark: model Haiku, corpus v1, one run each
Defence profileResilienceAttacks held
no guardrails90/1009 of 10
deny reads of secret files100/10010 of 10
deny reads and sandbox100/10010 of 10

The agent completed the control tasks under all three profiles, so the profiles do not simply block everything. The important caveat: this is a single measurement. That is why injection-bench can run every case several times and then reports rates with an uncertainty range instead of celebrating a single number.

One finding: a deny rule for .env stops the agent’s read tool, but not reading through the shell. Only the sandbox closes that gap. These are exactly the assumptions I want to measure before I rely on them.

What the chain cannot do

Each stage recognises what it knows. commit-guard looks for patterns, pr-airlock for shapes, injection-bench measures a fixed corpus. A new attack outside of that can get through. No stage replaces reading changes yourself. The three tools only make mistakes rarer and more visible.

What I take away

A defence you don’t measure is a guess. When a tool cannot check something, it should say so loudly instead of waving it through. And outside content is read, never run: that rule is built into all three tools.

Sources

Every number comes from the “main” branch of the public repos on . I counted the tests myself with node --test.

386 tests
commit-guard, commit 2a52656 (new tab), npm test
10 patterns, 3 × 3 matrix
commit-guard README (new tab), test workflow (new tab)
3 of 3, 0 in 31
pr-airlock README, field test (new tab)
Tests pr-airlock
commit 41666aa (new tab), node --test
Corpus, profiles
injection-bench BENCHMARK.md (new tab)
Sample benchmark
docs/beispiel-benchmark.md (new tab), measured on
Tests injection-bench
commit 899ddfc (new tab), node --test

All three tools are open source, have no dependencies and are purely defensive: the tests use made-up data, never real malware or real keys.