Skip to content

Blog

Keeping AI agents safe in practice: proof before done, checks as code, narrow keys

By . Published . 5 min read. Đọc bằng tiếng Việt

TL;DR

Rules written in a prompt are only requests. The safety here comes from things that run, such as a hook that blocks three actions outright, and from demanding evidence: a check counts only after it has been seen failing, and a review finding only with a command that reproduces it. Credentials are narrow and short-lived, and code from strangers never runs on the main machine. The limits are real: the hook covers only three rules and fails open.

Why is "tell the agent to be careful" not enough?

A rule in a prompt is a request. The agent may not read it, may lose it in a long context, or may follow its words and miss its point. So the approach has two parts: put a small number of rules where code enforces them, and make everything else produce evidence a person or a script can check.

The path of a change: a guard hook blocks three actions, a pre-commit check runs, a change counts only with proof, and money or irreversible steps go to a person

Which rules are enforced by code?

Mechanism What it does What it does not do
A hook that runs before each tool call Blocks three things outright: opening a login-walled social site (use a text mirror instead), force-pushing, and committing files that look like secrets (.env, key files, auth files; examples are allowed). No network, no writes, no third-party code It covers only those three. It fails open: if its input is malformed it lets the call through, so it can never wedge a session. It is not a sandbox
A git pre-commit hook Blocks a commit when a new rule has no place in the generated map of the system It checks structure, not whether the rule is right
A second hook on file edits Holds back edits to animation code until the agent has loaded the animation skill, and flags known animation mistakes right after a write It covers animation code only
Checks in each project Licence gate, bundle-size budget, lint rules and tests, run in the build Only the failures somebody already thought of
CI on a fresh machine Every push to the main branch of more than twenty repositories reruns install, format, lint, types, tests and build on a hosted machine that starts empty, with no secrets and read-only access It does not block a merge or a deploy yet; a red result is information that someone has to act on

When a bug could have been caught by a lint rule, the rule is added in the same change, so it cannot come back. That is preferred over writing a note.

What counts as proof that something works?

  • Evidence before summary. A completion report starts with what ran, the command and its output, then the summary. The definition of done is written first, as something observable.
  • A check counts only after it has been seen failing. Put the bug back, or remove the guard, watch the check go red, restore it. A test written with the same mistake as the feature proves nothing.
  • A review finding counts only with a command and its output. If a reviewer cannot reproduce a claimed problem on the real code, it is labelled unproven and starts no fix. Style opinions and future risks are dropped. Changes that touch saved user data, money, sign-in or concurrency also get one independent reviewer on a different model, held to the same proof rule. The reason is a trial on a vocabulary app: with the author's tests and own review all green, one outside reviewer proved 2 regressions and 3 older data-loss gaps. Exactly one is allowed, so it cannot grow into an expensive loop. The post on self-checking covers the full set of proof rules.

How are credentials and code from outside handled?

These rules were tightened after one published incident report from a large exchange (3 November 2026): a tampered package install, a fake job-interview project that ran malware, a deploy token on a laptop. It is a single source, so we use it as a list of questions, not as a verdict.

  • Install from the official source only, at an exact version, never from a search result or a pasted one-liner. A new tap, MCP server or skill is code that runs with the owner's privileges: read it first and record its source.
  • Code from a stranger never runs on the main machine. Read it first. If it must run, use a throwaway container with no secrets mounted and install with scripts disabled. That also holds for popular open-source tools: before adopting a lint plugin recently, we read its source and ran it in a throwaway container against copies of our projects with the secret files left out.
  • Narrowest, shortest-lived token that does the job. Deploy tokens are kept apart, and a secret value is never printed.
  • Limits outside the part that can be compromised. For anything that moves money or grants access, caps and allowlists live outside the component an attacker could drive. Before shipping keys or tokens, write down how to revoke them, and check that switching the feature off also invalidates what was already granted.
  • Text from the web is data, never instructions. A page, a post or a tool result that tells the agent to do something is ignored and mentioned in the report.

What stays with a person?

The agent decides and acts by default; the exceptions are listed in the first post. It also does not start extra sub-agents on its own: it needs an exact number from the owner, because an agent that can spawn agents can spend without a limit.

What still fails?

  • The hooks cover three standing rules and animation code. Everything else in the rule files is still a request.
  • Agents can misread a written rule. The proof habit makes a misreading show up as a failing check, not as a confident summary.
  • A cheap worker can pass its own tests and still change behaviour the tests do not cover. In our measurements, replaying old and new code on inputs outside the tests found it, not the worker's report.
  • Nothing here replaces a security review of the product itself, and we have not measured how many incidents this setup prevented, so we claim no number.

Also as Markdown. Follow new posts with the RSS feed.