pytest Ran the Payload. Every Check I Wrote Said Allow.
Two tool calls, each one fine on its own: write a conftest.py, run the tests. A 15 November paper puts numbers on that pattern, and my own gate passed both calls.
By Sattyam Jain · first published on Medium on · 5 min read
Edits on this site
- : The Medium version said "I run more than 15 agents in production at Attri". That is a retired figure; the current one is 100+ agents built at Attri.
This week I gave my own agent gate a test it should have failed loudly. It passed both steps.
The setup is two tool calls. The first writes a file called tests/conftest.py inside the repo the agent is working in. The second runs pytest -q. pytest imports every conftest.py it finds before it runs a single test, so whatever the agent wrote in that file runs with the same environment as the shell. In my run the file was three lines. It listed the environment variables ending in _KEY or _TOKEN and wrote their names to disk. It found OPENAI_API_KEY and GITHUB_TOKEN. pytest printed "1 passed".
agent-airlock, the runtime gate I maintain, allowed the write and allowed the test run.
Each call was allowed. The pair was the attack.
What the gate did right
I want to be exact here, because the gate did its job on every call it was shown.
The filesystem policy was the restrictive preset with the repo as the only allowed root. It refused a write to .git/hooks/pre-commit, because **/.git/** is on its deny list. Git hooks are the obvious version of this trick, and that door was shut.
The shell policy had an allow rule for pytest and defaulted to deny. It refused python -c with inline code. It refused curl ... | sh. Those are the commands a reviewer would flag by eye, and the policy flagged them without a model in the loop.
Then I ran agent-audit-kit, my static scanner, over the same repo. 508 rules, 0 findings. Three of its scanners skip conftest.py by name, because test files are where noisy findings come from. That choice made sense when I wrote it. It reads differently now.
The numbers from the paper
On 15 November, Deep Shah and Nehal Kathrotia posted “Compositional Exploits in Autonomous Coding Agents: Attack Mechanics and Ephemeral Defense” (arXiv 2611.19764). Their claim is that auditing each tool on its own misses the attack, because the attack lives in how harmless tools get chained across turns, through shared workspace files, environment variables, and chat memory.
Their benchmark has 560 tasks: 360 exploit tasks across eight hazard classes and 200 benign developer and cloud workflows. Unprotected Gemini 3.5, 3.7 and 3.8 Flash finished the exploit chains 72.9% to 84.5% of the time. Five single-tool scanners detected 0% of the tools involved.
Zero is the expected answer. Each tool was harmless, so a scanner that looks at one tool at a time has nothing to find. My conftest run is the same result at a smaller scale. A write inside the repo is fine. Running the tests is fine. You only see the problem when you hold both calls in your head at once.
This is also not new as a shape. MOSAIC (arXiv 2607.02857) showed CLI command composition against coding agents in the summer, and Gecko Security wrote in March about a test file inside an installed skill that runs during npm test. What the 15 November paper adds is a benchmark with a benign control, which is the part I care about. A defense that blocks the exploit and half of real work is not a defense anyone keeps switched on. They report a 98.0% solve rate on the benign set with their defense in place.
Why per-call checks felt like enough
I have built 100+ agents at Attri. Every gate I have built checks a call before it runs: the arguments, the path, the command, the destination. That model is easy to reason about. A call comes in, the policy says allow, ask, or deny, and the verdict depends only on the call.
That last property is what I liked. The model can retry and argue all it wants, and a denied command stays denied. It is also exactly why the conftest chain walks through. The verdict for pytest -q does not change based on what happened two calls earlier, by design.
The runners we use every day are full of files that turn “run the tests” or “build it” into “run whatever is in this file”:
- pytest imports conftest.py.
- npm test runs the test script in package.json.
- make runs the Makefile.
- Python runs the import lines in any .pth file in site-packages at startup.
- git runs hooks, which is why that directory is on my deny list in the first place.
Every one of those is an ordinary file an agent is expected to edit. Denying writes to all of them breaks normal coding work. Allowing them and also allowing the runner is the chain.
What airlock already has, and where it falls short
airlock has a data-flow gate (since 0.10.29). You tag a tool that brings in outside content, like a web fetch or an issue reader, as an untrusted source, and you tag tools that act outward as sinks. Once an untrusted source returns in a run, a sink in that run is refused or sent to an approver.
That would have caught this chain if the instruction came from a fetched issue and the file write was tagged as a sink. It does not help when nobody tagged the reader, or when the instruction came from somewhere the host does not treat as outside content. Tags are a deployment decision, and the default is no tags.
The paper’s defense goes further. It gives each step a lease for one skill and tracks where data came from, with Landlock and seccomp underneath, and reports 61.4 microseconds of overhead per interposition. That is the right direction. It is also a kernel-level setup most teams running agents on a laptop or in a CI job will not have this quarter.
The rule I want in my gate
The smallest thing that would have stopped my own run is a link between two calls that are each allowed:
- When the agent writes a file that a known runner executes on its own (conftest.py, package.json scripts, Makefile, .pth, hook directories), the session records it.
- The next call that starts that runner gets ask instead of allow, with the written file named in the prompt.
- A human who approves sees the diff of that file, not just the command.
That keeps both calls legal. It keeps pytest on the allow list for the 99 runs where nothing in tests/ changed. It moves the decision to the one moment where the two calls meet.
The cost is one extra question on the runs that matter. In my own sessions, the agent edits conftest.py rarely, and when it does, I want to read that diff anyway, because a fixture change can quietly make a failing test pass. So the prompt lands where a careful reviewer would already stop.
It will not catch everything. An agent can edit a source file that a test imports, and the runner will execute that too. But the autoload files are the cheap, high-signal case, and they are where a prompt injection goes first because they need no import to fire.
The decision rule I am taking from this, for any agent gate, mine included: if a call is allowed only because it looks harmless on its own, ask what the previous write made it mean.
Which runner in your setup executes a file the agent can edit without anyone reading it first?