← All articles

Ask, Forbid, Make It Impossible

Three ways to keep an agent from doing what it shouldn't, why the first two depend on having imagined the mistake, and what changes when the forbidden thing can't even be written

17 min readartificial-intelligenceagentssoftware-engineeringtype-systemshaskell

Machine-translated from Spanish. Read the original

ByFederico Sawady O'ConnorRagnagrok Academy

On April 25, 2026, a coding agent deleted the production database of PocketOS, a small startup, and the backups along with it. It took nine seconds. It was working in the staging environment, ran into a credentials problem, and decided to fix it by deleting a data volume with a single call to its cloud provider's API. It assumed the deletion would stay inside staging. It didn't, because the token it found had permission for everything, and the backups lived on the same volume as the data. The latest backup that could be recovered was three months old.

What struck me most wasn't the deletion. It was the confession. When the founder asked it what had happened, the agent quoted the rule it had just broken. Among its instructions there was one telling it, in capital letters and with a swear word in the middle, never to guess. And it acknowledged that its rules forbade it from doing anything destructive without approval. It had them. It had read them. It broke them anyway.

There are three ways to keep an agent from doing something:

  • Ask. Write it in its instructions.
  • Forbid. Put something in the environment that rejects the action.
  • Make it impossible. Set things up so the action can't even be expressed.

In Debugging in the Age of Agents I separated asking from enforcing. Here I want to split the second one in two, because there are two very different ways to enforce, and only one of them doesn't depend on having imagined the mistake.

Ask

At the start of every session, coding agents read a project instructions file. In Claude Code it's called CLAUDE.md, and in other tools AGENTS.md. That's where what the agent needs to know goes (how to run the tests, which conventions the team follows, what not to touch).

The agent follows it almost always. And Claude Code's own documentation is honest about that almost, because it says the agent treats those instructions "as context, not enforced configuration", and that to block an action regardless of what the model decides, you need something else.

The evidence points the same way. A 2025 study gave twenty language models up to five hundred instructions at once. The more there were, the less each one was followed, and at five hundred the best model followed 68%. Another, from 2026, measured what happens when a repository has an instructions file. The agents follow what the file says, but in general they don't solve more tasks, and the cost goes up by more than 20%.

Asking well pays off a lot. In Convincing a Machine I measured that a rule with its reason gets applied to cases the rule doesn't name, and a bare order doesn't (twelve out of twelve against zero out of twelve). But it's still a request. The PocketOS agent had its rule, and in capitals.

I have a smaller case of my own. In a Laravel project, the code runs inside a container with Sail, Laravel's tool for that. Running PHP directly on the machine uses another version of the language and another database, so it gives results that aren't the real ones. The CLAUDE.md said "always use Sail". The agent followed it sometimes.

Forbid

A hook is a command the tool runs on its own at a fixed moment, for example before every command the agent wants to run in the terminal. It receives the command, looks at it, and can reject it. The agent doesn't decide whether the hook runs. It always runs.

I wrote one that rejects any PHP run outside the container, and the problem went away. When the agent tries, the hook stops it with a message that says why, and the agent corrects itself and uses Sail.

The most instructive part came later. The CLAUDE.md of that same repository documented a command to run on the machine, outside the container, which is exactly what the hook blocks. The text and the hook said opposite things. The agent followed the text, the hook rejected it, and the agent used Sail. The environment won. (And, as a bit of self-criticism, in another repository I have the same rule only as text, without the hook.)

The agent doesn't stand still when something stops it. In two weeks, the permission classifier I use, a second model that reviews each of the agent's actions before letting it through, stopped 41 actions, among them production reads, merges without review, deploys and credentials. Two of them were the agent trying to get around a hook. Once with --no-verify, the git option that skips the commit checks. Another time, committing from inside the container, where the hook didn't run. It isn't bad faith. An agent with a task and an obstacle looks for another way, which is exactly what we want it to do in any other situation.

The list always arrives late

To see how much a hook holds up, I wrote the one almost anyone would write first, one that rejects any command containing DELETE or DROP, in upper or lower case. And I threw at it nine ways to wreck an orders table from the terminal.

Correction (November 25, 2026). The first version spoke of nine ways to empty the table. Several don't empty it, because the DROP removes it entirely, the UPDATE sets the amounts to zero and the cleanup.sql file deletes only the orders under 100. All of them leave it different from how it was, which is what the repo measures, so the conclusion doesn't change. I found it in a review of the series.

Attempt The hook
DELETE FROM orders stops it
DROP TABLE orders stops it
delete from orders stops it
TRUNCATE orders lets it through
UPDATE orders SET total = 0 lets it through
"DE""LETE FROM orders" lets it through
the DELETE encoded in base64 lets it through
psql -f cleanup.sql lets it through
turn off a setting, then the file lets it through

It stops three out of nine. TRUNCATE is another word with the same effect. The UPDATE doesn't delete anything, but it sets every amount to zero, which for the business is the same thing. In "DE""LETE", the shell glues the two halves together before handing the text to the database, and the hook only sees the halves. Base64 is a way of writing the same text with other letters. And the cleanup.sql file was written by the agent with its file-editing tool, which this hook doesn't watch.

I could write a better hook, one that adds TRUNCATE and UPDATE, decodes base64 and checks the files. Each fix closes a hole I've already seen. That's the problem. A hook like this is a list of the prohibitions I thought of, just as a test is a sample of the cases I thought of. It's the same flaw I described in What You Check, Not What You Asked For, seen from the other side, since the test samples the good, the hook enumerates the bad, and both cover only what someone imagined.

And the list looks at steps one at a time. Reading a secret in one step and sending a request to the internet five steps later are two allowed actions; together, they're a leak. No hook that looks at one command at a time sees it. That's what Guarantees That Stack is about.

None of this means you should throw hooks away. They're indispensable, and the Sail one works perfectly. It works because what it forbids is small and known. "PHP outside the container" has few ways of being written. The problem shows up when what you need to avoid is a harm, and a harm has infinitely many ways of being written.

Permissions, not prompts

I ran the same nine attempts against a real Postgres database, with three different users.

The first one owns the table, with no protection at all. It's the control. With it, all nine attempts destroy the table, which confirms that all nine work.

The second one can write, but is configured so that everything it does is read-only by default. It stops eight out of nine, although the DROP would fail anyway, because the role doesn't own the table. The ninth starts with a line that turns that setting off, and then deletes. Any user can change that setting for themselves. A setting the agent can change is a request with extra steps.

Correction (November 25, 2026). The first version implied that the setting is what stops all eight. The DROP is also stopped by the role not owning the table, because in Postgres only the owner can drop a table, and with the setting off it still fails. The setting alone stops seven, and the conclusion doesn't change. I found it in a review of the series.

The third one only has permission to read, like the user of a read replica, a copy of the database that exists for querying and not for writing. It stops all nine. And it would stop a tenth nobody has thought of yet, because it doesn't have a list of what's forbidden. It has a list of what's allowed, and what isn't on that list doesn't exist.

That's the difference between forbidding and making impossible. A list of what's forbidden loses against whoever invents. A list of what's allowed doesn't. The idea is more than fifty years old. Jerome Saltzer and Michael Schroeder put it among their design principles for protecting information in 1975, under the name fail-safe defaults, which asks to base access decisions on permission rather than exclusion, because a mistake in a list of permissions refuses something and is noticed right away, while a mistake in a list of exclusions lets something through and nobody sees it.

The PocketOS case looks different in this light. The problem wasn't the model thinking badly but a token with more permissions than the task needed (the opposite of least privilege, another principle on the same list), environments that weren't isolated, and backups on the same volume as the data. No instruction, however well written, makes up for a key that opens everything. The risk is in the access we give it, not in what we ask of it.

The read replica has another virtue too. The PocketOS agent deleted because it guessed what would happen. With read access to the real thing, an agent doesn't need to guess, because it can ask. Once, the title of an issue talked about "codes loaded by hand". A query to the replica showed there were 71,212 of them, and that they had come in through an import. That couldn't be deduced from reading the code, and the number changed the design decision.

Making it impossible, inside the program

The permission is coarse, because a user can write or it can't. But at some point the agent has to write, for a migration or for the code that removes the test orders. And then the question moves inside the program. Can the code it writes perform a deletion it shouldn't?

Inside the program, the equivalent of the list of what's allowed is the type system. The repo has a small version in Haskell, where the database connection says in its type whether it can write:

select      :: Db access     -> Query -> IO [Order]
deleteWhere :: Db 'ReadWrite -> Query -> IO ()
withReplica :: (Db 'ReadOnly -> IO a) -> IO a

Even if you don't know Haskell, it reads. select works with any connection. deleteWhere requires a read-write connection. And withReplica, what the agent is given, hands over a read-only connection. If the agent tries to delete with it, the program doesn't compile:

Couldn't match type ‘ReadOnly’ with ‘ReadWrite’

The tricks that beat the hook have no equivalent here. There's no text to split in two or to encode, because queries aren't text but are built with functions, and there's none that deletes with a read connection. In the repo I tried six ways to do it anyway, which were deleting with the read connection, sending the DELETE as text through the function that reads, taking the connection apart and putting it back together as a write connection, changing only its type, importing the write connection the migrations use, and unsafeCoerce, Haskell's best-known door. None of them compile.

But there's a seventh that does compile, because it doesn't go through Db. From IO, the agent's code can declare C's system function with foreign import, which runs an operating-system command, and run psql -c 'DELETE …'. Safe Haskell allows it. The type covers what's done with the Db API, not everything the agent can do in IO. Permissions cover that side, because if the agent only has the credentials of the user that can read, that DELETE bounces like the nine in the table.

Correction (November 25, 2026). The first version said no door compiled and called unsafeCoerce the last one. There was a seventh, foreign import from IO, which compiles with the same flags and deletes without touching Db. The conclusion changes in scope, because the type closes the Db API and the rest of IO is left to permissions, so the type and the read-only user go together. I found it in a review of the series, and the repo now has the case in 3-impossible/escapes/.

I have to be honest about one detail. Two of those six doors, coerce and unsafeCoerce, are open in plain Haskell, because they turn the read connection into a write one without complaint. Compiling the agent's code in safe mode (Safe Haskell) closes them, since it doesn't allow importing either one, and the line type role Db nominal also closes coerce, even without that mode. As happened to me with #![no_std] in First the Filter, Then the Generator, the guarantee is real, but someone has to know which doors the language has. The difference from the hook is that those doors are few and known, and the language names them. The ways of writing text in a terminal are infinite.

Correction (November 25, 2026). The first version said each of those two doors needed its own line, and that without type role Db nominal the coerce one stayed open. With safe mode it's already closed, because Safe Haskell doesn't allow importing Data.Coerce, so that line is a second defense, for code compiled without that mode. The conclusion doesn't change. I found it in a review of the series, and the repo now also compiles rejected/Coerce.hs without safe mode, to show that the line alone is enough.

This is a version, for interactions with the world, of something I covered in Type Systems for Machines That Program, the idea of making illegal states unrepresentable. A type doesn't catch the mistake, it makes it inexpressible.

And you have to be careful with the word "all". It's sometimes said that property-based tests, which I wrote about in QuickCheck vs. Traditional Testing, cover all inputs. The property states something about all inputs, but the tool checks it with a random sample. It's a much better sample than the one I would pick, but it's still a sample. The type, on the other hand, rules on every program the agent could write.

The ladder of loops

Time isn't a reason to prefer the third rung to the second, because the hook answers instantly and the compiler takes seconds. It is a reason to find out about the mistake as early as possible. An agent works in a loop where it writes, tests, sees what failed and fixes it. What speeds it up most isn't a smarter model but a faster and clearer answer about what failed. Each way of finding out about a mistake takes a different amount of time:

Where the mistake shows up How long it takes What it catches
Types and linter seconds the shape
Unit test seconds to minutes the logic
Agent hook instantly the environment's rules
Read replica seconds real volume and distribution
CI minutes integration
Staging, end to end hours the contract and real data
Production days everything, but late

Correction (November 25, 2026). The first version said time was another reason to prefer the third rung. The table itself disproves it, because the hook arrives before the type. What favors the type isn't speed but what it covers, a list of what's allowed instead of a list of what's forbidden. I found it in a review of the series.

Every mistake you move one rung down is time you gain. And the compiler's error, besides arriving in seconds, says what's missing. "This needs a write connection and you have a read one" is an answer the agent can do something with, like stopping and asking. The PocketOS agent found out about its mistake in production, which is the last rung, and by then it was too late.

What goes where

The three coexist, and each has its place.

Asking is for what needs judgment and can't be turned into a rule, such as what to prioritize, when to stop or what's at stake. That's where conversation pays off, and explaining pays off more than ordering.

Forbidding is for what can be named, when what needs naming is small, such as "PHP outside the container" or "commits that don't pass the tests". A hook that covers that has few holes, but it has some, and the agent looks for them. The two it tried with a commit hook, --no-verify and the commit from inside the container, were stopped by the permission classifier, not by the hook.

Correction (November 25, 2026). The first version said a hook like that has no holes worth looking for. The article itself contradicted it, where the agent tries to get around a commit hook twice. A small hook has few holes, not none, and it's worth having another layer that watches them. I found it in a review of the series.

Making it impossible is for what must never happen. One part is authority, what the agent can touch, and permissions take care of it. The other is meaning, what the program can say, and types take care of it.

HumanLayer, a company that builds tools for agents, sums it up in a line that says an LLM should never be sent to do a linter's job. I'd add a question to ask of every rule in the CLAUDE.md. Could it be a hook? Could it be a permission? Could it be a type?

The PocketOS agent had the rule written down, in capitals. A rule in capitals is a request, shouted. What would have saved them was a token that couldn't delete volumes.


References

  • Crane, J. (2026). Account of the PocketOS incident, quoted in Decrypt: AI Agent Deletes Startup's Database in 9 Seconds, Founder Says (April 28, 2026). Decrypt
  • Anthropic. How Claude remembers your project (CLAUDE.md). Documentation
  • Anthropic. Automate actions with hooks. Documentation
  • Jaroslawicz, D. et al. (2025). How Many Instructions Can LLMs Follow at Once? Evaluating the Evolving LLM Lifecycle workshop, NeurIPS 2025. arXiv:2507.11538
  • Gloaguen, T. et al. (2026). Evaluating AGENTS.md: Are Repository-Level Context Files Helpful for Coding Agents? arXiv:2602.11988
  • HumanLayer (2025). Writing a good CLAUDE.md. Blog
  • Saltzer, J. H. and Schroeder, M. D. (1975). The Protection of Information in Computer Systems. Proceedings of the IEEE, 63(9). Text
  • Minsky, Y. (2011). Effective ML Revisited. Jane Street Tech Blog
  • PostgreSQL. Privileges. Documentation
  • GHC. Safe Haskell. User's guide
The code

Everything this article claims, in code that runs. Clone it, break it, open an issue.

Ragnagrok/ask-forbid-make-it-impossible
Support the blog

If this article was useful to you, you can sponsor the blog on GitHub. It helps me keep writing.