---
title: 'Rules a coding agent cannot talk its way round'
canonical: 'https://www.dealmobile.co.uk/writing/rules-a-coding-agent-cannot-talk-its-way-round'
url: 'https://www.dealmobile.co.uk/writing/rules-a-coding-agent-cannot-talk-its-way-round'
type: Post
published: '2026-12-02'
summary: 'The hook that reads every command a coding agent wants to run on my Linux boxes: what it refuses, the 27 proofs that its tests fail when a rule is taken out, and the four lines every report opens with.'
---

# Rules a coding agent cannot talk its way round

Published 2026-12-02

![Two commands. The first, rm -rf with a variable as its target, is refused: it could delete or overwrite / when a variable in it is empty. The second, a delete of a literal scratch path under /tmp, is allowed.](https://www.dealmobile.co.uk/sites/default/files/styles/almanac_shot_md/public/content/images/posts/rules-a-coding-agent-cannot-talk-its-way-round/hero.png.webp?itok=W8DXJvjI)

My coding agents run with the permission prompts switched off. They work unattended, and a prompt stops all of it until I’m back at the keyboard.

That leaves written rules. I had three that mattered: never delete on the home folder or `/`, never copy one of my local databases over another, and publish nothing. The database one exists because a session spent over an hour piping a dump of one database into another, when those databases are disposable and a script builds a fresh one. All three now have code behind them as well as text.

## The hook

Every shell command an agent wants to run goes to a hook first. The hook gets the command and the working directory as JSON, and answers allow, or deny with a reason the agent reads. It’s Python. A command with none of `rm`, `mv`, `-delete`, `rsync`, `clean`, `dump` or `sql` in it skips the safety checks altogether.

This is a refusal:

```
$ rm -rf "$BUILD_DIR/"
Refused: `rm -rf '$BUILD_DIR/'` could delete or overwrite / when a variable in
it is empty. Never delete, move over or sync --delete onto $HOME, ~, /home/<me>
or /, or a target that is only a variable. The allowed way: make scratch space
with `mktemp -d` (under /tmp or the session scratchpad), use its literal path,
and delete only that literal path, or a literal path inside the repo. Do not
change settings or hooks to get past this check.

```

It reads `~`, `$HOME` and `${HOME}` as the home folder. `/`, `/home` and my home folder are always protected. It refuses a recursive delete whose target is only a variable, and `find -delete` or `find -exec rm` on a protected folder. `rm -rf /tmp/tmp.Ab12Cd34/out` goes through.

So does `rm -r` on a folder inside my home. The hook protects the home folder itself and leaves what’s in it alone, and anything it can’t work out (a `cd` into a variable, an unknown working directory) it allows, because a false refusal stops unattended work the same way a prompt did. An agent deleted a cache folder in my home that way. It was 55 MB and the program that owned it rebuilt it. The written rule covers that case and the code doesn’t.

The database check looks for a dump piped into a load, `mysqldump`, `mariadb-dump` or `mydumper` into `mysql`, `mariadb` or `myloader`, on the databases the rule is about. Its refusal doesn’t repeat the command, because a database command line can carry a password.

Publishing isn’t in the hook. The two tools that can put a page on a public link are on a deny list in the agent’s settings, so they can’t be called at all.

If the hook crashes, the command runs and a warning is shown. A guard that fails closed would stop every session on both boxes at once.

## Two more rules in the same place

The hook’s first job was a different one. On the box I carry it refuses test suites, installs and builds, and prints the command that runs the same thing on [the box at home](https://www.dealmobile.co.uk/writing/two-linux-boxes-kept-in-step.md).

A second hook sits on delegation, where one agent hands a task to another. It refuses a task given to the most expensive model, and one given to the next model down unless the brief carries a line with the reason. Before switching it on I replayed it over the previous seven days: 263 delegated tasks, 97 of them on that second model, none with a reason line. It would have refused 37 per cent of them, so it started in warn mode.

## Tests that have to fail

A guard’s tests passing tells me little unless they fail when the guard is gone. So there’s a file of 27 proofs, and this is one:

```json
{
  "id": "safety-bare-var",
  "rule": "a recursive delete whose target is only a variable is refused",
  "old": "        return \"anything (the target is only a variable, which may be empty)\" if bare else None",
  "new": "        return None",
  "test": "tests/test_safety_guard.py::test_destructive_deny"
}

```

A runner copies the repo into a fresh scratch folder for each proof, swaps that one line and runs the named test, which has to fail. It runs every named test on an unchanged copy first, so a failure means the change and not a broken test. Nine proofs cover deletes and database copies, seven the heavy-work rule and eleven the delegation rule. All 27 fail when they should.

The runner was the risky part to write, since it edits guard code and runs things. Its second review found that a test name starting with `-` reached pytest as an option and deleted a file outside the scratch folder through `--basetemp`, and that the run inherited my tokens and my ssh agent. Both are fixed, with tests. The test run now gets an environment built from an allowlist, with `HOME` inside the scratch folder.

Reviewers have a rule of their own from an earlier job. A reviewing agent, probing a guard, tried its commands in the real repo with the real login and pushed three commits. A reviewer’s probes now run in a scratch clone with no credentials.

## Four lines on every report

Work an agent hands back opens with four fixed lines. This is a real one, trimmed, from an agent reviewing a shell script of mine that removes folders on another machine:

```
STATUS: done
MODEL: <the model it ran on>
HEAD: worked from 86d3105 (uncommitted changes); left unchanged, no edits or commits.
NOT VERIFIED: the real script against real `sudo` or `ssh`; real `sudo -A` stdin
behaviour; the flush on a real terminal (I only confirmed `tcflush` fails with
exit 1 off a terminal); how sshd treats the remote `bash -s` when the link drops.

```

`MODEL` is there because naming a model in a brief isn’t proof the agent ran on it. `HEAD` is the commit it started from and the one it left. `NOT VERIFIED` may say `nothing` only when that’s true. That last line was the list of what I still had to try myself.

The idea for the header and for the proofs came from [someone else’s public repos](https://www.dealmobile.co.uk/writing/61-public-repos-of-agent-tooling-none-installed.md). The suite around the hooks had 2,294 tests when the proofs went in.

- **Tags:** [Security](https://www.dealmobile.co.uk/writing/tag/security.md), [Testing](https://www.dealmobile.co.uk/writing/tag/testing.md), [Agents](https://www.dealmobile.co.uk/writing/tag/agents.md)

---

Index of this site: [llms.txt](https://www.dealmobile.co.uk/llms.txt)
