Last week an engineer asked me a question I couldn't answer cleanly: "My agent posts a confirmation dialog before it touches anything dangerous. Isn't that enough?"
No — and the reason is structural, not a matter of making the dialog prettier.
By the time the dialog appears, the model has already decided what to do. The human is shown a blob of arguments and asked to judge intent from it. That's the wrong job for a human at 11pm: we skim, we click "allow", we learn to click "allow" because the dialog fires forty times a day.
Worse, the dialog is a request layer. Anything expressed as a request can be argued with. A model that decides the gate is inconvenient will produce arguments that look reasonable — narrower paths, friendlier flags, a "small" scope. You are not auditing; you are negotiating.
A useful gate sits between the model's decision and the tool's effect, and it is evaluated by code the model does not author and cannot edit mid-run.
The contract I use is deliberately boring:
That last point is the one people skip, and it is the one that matters. A gate that fails open is decoration. A gate whose failure is indistinguishable from a denial teaches you nothing about your agent. Keep the two signals separate in your logs: hook_deny and hook_error are different events, and if you merge them you will never notice a gate that has been silently broken for a month.
Refusing a DROP TABLE is good. Not letting the agent construct a statement that could drop anything is better.
Practical version: the gate operates on a small, explicit taxonomy — read, write within a root, execute, network egress, irreversible. Anything that doesn't classify cleanly is denied by default. You stop writing regexes for every awful command in the world and start asking one question: does this call have a shape I have already decided is safe?
This is also where path canonicalisation belongs: proj/../../etc is a different string and the same file. Check the resolved path against the allowlist root, not the string the model typed.
Not by the model. Every gate invocation writes: timestamp, session id, tool, the arguments it judged, the decision, and the reason. Now "why did it do that?" is a grep, not an archaeology project.
Two properties matter more than the format:
Honesty section, because every "secure agent" post is missing one:
bash can do whatever the user can.
The uncomfortable conclusion: you cannot ask a human to approve every step, and you cannot trust the model to police itself. What you can do is make the dangerous step unrepresentable, make every decision legible, and make failure loud.
If you want to see the contract I described wired into a real runtime, I built it into GAL — a local, single-binary agent runtime with the gate ahead of tool execution and kernel-level sandboxing underneath. The interesting part isn't the product; it's that the gate is a process boundary, not a prompt. What does your gate do when it panics? If the answer is "allows the call", that's the bug to fix this week.