Writing · AI systems
A rule the model can break is a suggestion
I told an agent not to write to git while it ran unattended. The rule was broken twice in an hour. It is now a check in code, and this is how that check is built and how I know it works.
I run coding agents unattended on my own machine, sometimes overnight, in a harness I built for myself. One of the rules in their instructions said: no git writes while running on autopilot. Commits and merges belonged to a different step.
The rule was broken twice in an hour.
I don’t think the model was being defiant. A prompt is a long document, and one sentence in it competes with every other sentence and with the task in front of the model. At some point a commit looked like the helpful thing to do, and the sentence lost.
So I stopped treating it as a sentence. When the harness starts an unattended turn, it sets a flag in the process environment. A hook reads every shell command before it runs. If the flag is set and the command writes to git, the command is refused. The model cannot override that.
A rule in a prompt is a request. If breaking it would hurt, it has to live somewhere the model cannot edit.
What the guard does
The agent CLI I use lets you register a hook that sees each tool call before it executes. Mine sits in front of the shell tool. It blocks three kinds of command outright: test runners, the framework commands that drop or rebuild a database, and destructive SQL. Those three are there because agents run them with the best intentions. A test suite pointed at the wrong database is a data-loss event that looks like diligence.
Three decisions in it took longer than the rules did.
It matches at command position. Searching a file for the text of a blocked command is fine. Running it is not. A guard that will not let an agent read about a thing gets switched off within a week, so the matcher looks at what is being executed and ignores the same words inside a quoted argument.
It fails closed. The hook protocol has two meaningful exit codes: 0 allows, 2 blocks. My wrapper turns every other exit code into a block. The comment in the source gives the trade: “A false positive costs ten seconds.”
It finds its own code without asking the environment. The wrapper resolves the evaluator’s path from where the wrapper itself sits on disk. The model can set environment variables. It should not be able to point the guard at a different script.
The guard that would have waved everything through
The second of those was not true at first.
The wrapper handed off to a Python script. A syntax error makes Python exit with code 1. Under the hook protocol, 1 is not a block. A typo in the guard would have turned it into a guard that allows everything, and its log would have gone quiet, which is what a well-behaved agent looks like too.
No incident found that. A mutation test did. I had a red-team suite: a list of commands that must be blocked, which exits 0 only if every one is. I wanted to know whether that suite could fail, so I had a second one built that breaks the guard on purpose, one rule at a time, and checks that the red team notices. Its header says what it is for: “prove the red team can actually FAIL”. One of the breaks was a syntax error, and with it the guard allowed everything.
Things that are missing on purpose
A check can be argued with, or have a bug. An operation that was never built cannot.
My machine has a network fence around the agents: a list of outbound connections they are not allowed to open. The tool the agents get for it has two operations: read the status, and raise the fence. Turning it off is not something an agent can do. The note in the source says a worker must never be able to lower the very fence that exists to contain workers.
A file reader I built for assistants is the same idea. It has no write, delete or move. Those operations were never written.
Tests get one door. Agents cannot run a test suite directly, because the guard blocks it. One command runs tests, with the network cut and the environment scrubbed, and before every run it proves that an outbound connection fails. If it cannot prove that, it does not start.
Choose which way each guard fails
One guard fails open, and it is meant to. It stops agents running long jobs in the foreground, where an idle timer would kill them. That guard is for convenience. If it breaks, I want the work to continue. Which way a guard fails is a choice you make for each one, and it is worth writing the choice at the top of the file.
The step people skip
Moving a rule from the prompt into code is the easy part to agree with. The step that gets skipped is the last one: break the code on purpose and check that something tells you.