A filter is not a wall: what two weeks of guarding one script from our own agents taught us
I spent two weeks trying to keep our AI coding agents away from one production script, first with a filter on their commands and then with a prompt on a terminal. Neither is a security boundary. A barrier is as strong as what the actor on the other side lacks, and for this script that part is still not built.
Our game server is one database module. Publishing it to production cannot be rolled back: a bad publish is fixed by publishing again, with players connected. So that step is mine, from my own terminal.
The AI agents that write most of our code work in the same checkout, with a shell. In mid-November we wrote one script that runs the whole publish, so that my terminal would refuse the same bad publishes an agent session already refused. That left an obvious question. What keeps an agent from running the script?
This is an account of how I answered that wrongly for a while, and what I think now.
The filter
Our agent tooling lets a small program, a hook, read every shell command before it runs and refuse it. We already had one that refused risky commands naming a production database. The new script did not name a database on its command line, so the hook could not see it.
The fix seemed plain: refuse any command that names the script, unless it only reads the file or runs its dry check. The first version went in on the afternoon of November 20. Its commit message says the rule “fails closed” and covers every bypass found in review. Both were true that afternoon.
Then a second reviewer, an AI model given only the diff and the ticket, was asked to break it. It tested candidate commands against the filter’s own code. Nothing in this story was run against production, and no agent ever tried to publish. Every hole below was found in review.
Three examples show the pattern.
publish-modu''le. The filter looked for the script’s name and did not find it. A shell deletes the empty pair of quotes before it opens the file, so it finds the script.publiſh, spelled with the old long s. To the filter, a different word. Our Mac’s filesystem treats it as the same letter and opens the same file.m$1odule. A shell replaces$1with nothing here, which leaves “module”. The filter’s guess at what the shell would do was off by one character.
Each round, I fixed what was found. The list of bad commands became a list of allowed ones. The filter learned to imitate how the shell rewrites a command before running it, and the next round found where the imitation was wrong. Four fixes landed between ten that night and midnight. The suite of deliberately broken copies that proved each fix grew from 12 to 42.
Round 5’s fix refused any command with shell punctuation whose letters spelled “publish”. It closed that round’s findings. It also refused a commit message that mentioned publishing.
That was the point where the work was plainly getting worse per hour. A filter reads text. A shell runs a language: it expands, substitutes and rewrites the text first. Whoever writes the command gets to work in the space between the two. I had been treating each finding as a bug. It was the design.
The next evening we cut the rule back to something a person can read, down to 25 test mutants, and wrote into the audit document what it does and does not do: it stops the documented command and the honest mistake. It does not stop a disguise.
The filter costs something on ordinary days too. A few days earlier, a harmless command that only mentioned a guarded database’s name was paused by the same hook for approval. It waited four and a half hours, because nobody was at the desk. And while collecting material for this article, the agent drafting it had a read of the script refused, because it joined two harmless commands with a semicolon.
The prompt
Forty minutes after simplifying the filter, we added something different to the script itself. A real publish now refuses to start unless it is attached to an interactive terminal, and then waits for the database’s name to be typed back. No flag skips it.
An agent’s shell tool has no terminal attached. So a run that got past the filter, through a copy of the script or a disguised name, would stop here. This was a different kind of safeguard: not a judgment about text, but a fact about the caller.
We were pleased with it for about two days.
On November 23 a review marked our own documentation as wrong. The docs said the prompt stops a run the filter cannot see. The review listed three ways past it. One of them: a pseudo-terminal, which is a program that presents itself as a terminal to another program. The same day, our own test of the prompt started using one, so it could type the name the way I would. If our test can do that, an agent can.
So the prompt does not prove a person is present. It proves a terminal is present, and a terminal can be made. We changed the docs to say that the prompt catches accidental runs only.
What I should have asked
The safeguards sort by what each one depends on.
| Safeguard | It holds as long as | What it is good for |
|---|---|---|
| A rule in the instructions | the agent reads it and complies | everyday guidance, reversible things |
| A filter on the command’s text | the filter reads text the way the shell runs it | the documented command, the honest mistake |
| A confirmation prompt | nobody builds the thing it checks for | the accidental run, a pause before something permanent |
| An absent capability | nothing the agent does | a deliberate attempt |
The first three are worth having. Ours catch real mistakes, and we kept all of them. The error was mine: I asked the second row for the guarantee that only the fourth can give. More care does not turn a filter into a wall. It makes a more expensive filter.
The way I say it now: a barrier is as strong as what the actor on the other side lacks. Not what it is told. Not what its words look like.
Other people knew this already
None of the references below were open during those two weeks. I read them afterward, for this article, and found our experience described in each.
The idea that a check on input is really a second, weaker interpreter of that input, and that trouble lives where it disagrees with the real one, is the core of a research program called LangSec. Listing what is allowed instead of what is forbidden was named “fail-safe defaults” by Saltzer and Schroeder in 1975. Keeping several imperfect layers, because each has holes in different places, is defense in depth, and James Reason’s Swiss cheese model is the usual picture of it. Workplace safety has a ranking, the hierarchy of controls, that puts removing a hazard above any rule about how to behave near it.
Even the terminal lesson was on record. A Red Hat bug from 2013 ended with Red Hat’s sudo package no longer requiring a terminal by default: a forced one satisfied the check. And the documentation for the agent tool we use says that permission patterns constraining a command’s arguments “are fragile”, and to pair them with a sandbox when a restriction must hold.
What is not done
The fourth row is still empty for this script. An agent in my checkout runs as me, on my machine, with my login to the database host. If one set out to publish, the filter and the prompt would slow it down and nothing would stop it. We have never seen one try.
The real fix is to keep the production credential somewhere the agent’s shell is not. That is future work, and it is only a boundary under two conditions: the agent cannot get the credential on its own, and it cannot reach some other path with the same power, such as a build job or a second machine that would publish for it. If either is false, I will have built a third tripwire and called it a wall again.
I spent two weeks learning how to tell an agent no more precisely. The question I start with now is different: should it be holding this at all?