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.
A dialog asks a human to re-parse JSON
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.
Rule 1: gate the execution, not the intention
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:
- run the gate before the tool executes, with the tool name and its raw arguments on stdin;
- if the gate wants to allow, it exits 0 and prints nothing;
- if it wants to deny, it exits 0 and prints the reason on stdout — that reason is returned to the model as the tool result, so the model can adapt instead of retrying blindly;
- if it crashes, exits non-zero, or hangs, that is an error, not a denial.
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.
Rule 2: make the dangerous case unrepresentable, not just refused
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.
Rule 3: one log line per decision, written by the gate
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:
- Append-only and outside the agent's workspace. If the agent can rewrite its own audit trail, it isn't one.
- The denial reason is reused, verbatim, in the log and in what the model sees. Same string in both places means your post-mortem reads exactly what the model read.
What this does not solve
Honesty section, because every "secure agent" post is missing one:
- The gate runs outside the sandbox. If the gate script itself is compromised or misconfigured, you have a hole with good logging.
- Gates don't stop a host that is already hostile — they bound what a model can talk the runtime into doing.
- A gate is a policy engine, not a sandbox. You still want kernel-level confinement for the process tree, otherwise a permitted
bashcan do whatever the user can. - And per-hook timeouts are easy to forget: a hanging gate looks exactly like a slow tool until your run mysteriously stops.
The shape of the fix
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.


