Originally published at heycc.cn. This is a mirrored copy — the canonical version is kept up to date at the source.
AI Agent Safety Guardrails: Human Approval, Sandboxes, and Audit Logs (2026)
The moment an AI agent can call a tool — run a shell command, hit a payment API, delete a row — it stops being a chatbot and becomes a process with side effects. The interesting question is no longer "is the output correct?" but "what is the worst thing this agent can do before a human notices?" Guardrails are how you keep that answer small.
Picture an agent that gets prompt-injected into running DELETE against production, or one that simply loops and charges a card twice. Four layers, stacked, keep that blast radius small: a tiered permission model, human approval for irreversible actions, a sandbox boundary, and a tamper-evident audit log. Each is grounded in published guidance from OWASP, NIST, and Anthropic, and each is something you can ship this quarter.
Why guardrails live below the model, not in the prompt
OWASP's 2025 Top 10 for LLM Applications names this risk directly: LLM06:2025 Excessive Agency. It traces the vulnerability to three root causes: excessive functionality, excessive permissions, and excessive autonomy. The third means the application "fails to independently verify and approve high-impact actions." Crucially, OWASP frames Excessive Agency as the vulnerability that enables damaging actions in response to unexpected, ambiguous, or manipulated model outputs, whether the trigger is a hallucination, a prompt injection, or a fully compromised agent.
That framing has one unavoidable consequence: a guardrail you implement by instructing the model in a system prompt is not a guardrail. If the model's output is the thing you don't trust, you cannot rely on the model to police itself. The enforcement has to sit in a layer the model can't talk its way past. Claude Code makes this explicit. Its permission rules are "enforced by Claude Code, not by the model," so instructions in the prompt shape what the agent tries, never what the system allows.
OWASP's eight prevention strategies for Excessive Agency form a useful checklist. The four layers below map onto them directly, plus two further OWASP-cited measures (logging/monitoring and rate-limiting) that the framework explicitly frames as damage limitation rather than prevention:
| OWASP prevention strategy | Guardrail layer in this guide |
|---|---|
| Limit permissions via least privilege | Tiered permission model |
| Require human approval for high-impact actions | Human-in-the-loop checkpoints |
| Avoid open-ended extensions (e.g. raw shell) | Sandbox + narrow tool surface |
| Execute in individual user context | Sandbox isolation |
| Complete mediation (auth in downstream system) | Enforcement below the model |
| Activity monitoring + rate limiting (OWASP frames these as damage limitation, not prevention) | Audit log + abort backstops |
Layer 1: Classify every tool, then assign a tier
Before you can gate anything, you have to know what each tool does to the world. The two axes that matter are reversibility (can you undo it?) and blast radius (how far does the damage spread?). This is exactly NIST's AI RMF Map function applied to tools: classify each action before you try to manage it.
Here is a four-tier model you can drop into a config file. It mirrors how Claude Code's permission system actually behaves: rules evaluated in a fixed deny → ask → allow order, designed to "fail closed" so any unmatched command defaults to requiring manual approval, with read-only access granted by default.
| Tier | Examples | Default behavior | Reversible? |
|---|---|---|---|
| Auto-run | Read file, search, list, GET request | Execute, log only | Yes — read-only |
| Log-only write | Create draft, write to a scratch branch, append to a queue | Execute, log with full payload | Yes — easily undone |
| Human approval | Send external email, charge a card, deploy, DELETE/DROP, modify prod config |
Pause and route to a person | No — irreversible / high blast radius |
| Blocked |
rm -rf /, raw shell on prod, credential exfiltration paths |
Refuse outright | N/A |
The decision rule is simple: default to the most restrictive tier, and promote a tool only when you have a reason. A new tool with no classification lands in "human approval," not "auto-run." This is the principle of least privilege expressed as a default, and it is the single highest-leverage choice in the whole design.
Layer 2: Human approval for irreversible actions
Anthropic's Building Effective Agents is explicit about where humans belong in the loop: agents "can then pause for human feedback at checkpoints or when encountering blockers." Its companion guidance on safe and trustworthy agents says when those checkpoints matter most: "humans should retain control over how their goals are pursued, particularly before high-stakes decisions are made." It gives a concrete example. An expense-management agent that finds the company overspending on subscriptions should get human approval before it starts cancelling them. The pattern generalizes to every irreversible, high-blast-radius action: approving a payment, deleting data, emailing a customer.
Note the word irreversible. You do not gate everything. That trains reviewers to rubber-stamp, and it destroys the value of automation. You gate the tier-3 actions from the table above. A good approval payload gives the reviewer enough to decide in seconds:
- What the agent wants to do (the exact tool call and arguments)
- Why (the reasoning trace or the user request that led here)
- Blast radius (how many records, which environment, what dollar amount)
- A one-click approve / deny / edit, with a default of deny on timeout
This is where a dedicated approval surface pays off: the four fields above are the minimum an approver needs to decide in seconds rather than reflexively rubber-stamping, which is its own failure mode.
Backstops: stopping conditions and denial-based aborts
Approval gates protect against bad individual actions. You also need to protect against an agent that loops, thrashes, or is being steered by an injection. Anthropic recommends stopping conditions such as a maximum number of iterations to maintain control. Claude Code's Auto Mode adds a sharper pattern: an output-layer classifier evaluates each action before it executes as a stand-in for a human approver, and escalates to a human as a hard stop after 3 consecutive denials or 20 total. A denial-based abort like this is a cheap, powerful backstop against an overeager or compromised agent. If it keeps trying to do things the policy refuses, that is the signal to halt.
NIST formalizes this as a governance requirement, not a nicety. AI RMF MANAGE 2.4 requires that mechanisms exist and responsibilities are assigned "to supersede, disengage, or deactivate AI systems that demonstrate performance or outcomes inconsistent with intended use." That is the authoritative basis for a kill switch.
Layer 3: The sandbox boundary
The only safe place to let an agent run open-ended code — raw shell, arbitrary scripts, untrusted tool extensions — is inside a boundary where the worst case is "we throw the container away." Anthropic labels Claude Code's --dangerously-skip-permissions flag exactly that dangerous: current docs warn to "only use this mode in isolated environments like containers, VMs, or dev containers without internet access, where Claude Code cannot damage your host system," and add that the mode "offers no protection against prompt injection or unintended actions." Isolated means isolated: not development machines, not shared servers, not anything with a path to production.
The rule that falls out of this: bypassing approvals is only acceptable behind a sandbox boundary. If an agent runs with permissions disabled, it must be in an environment with no production credentials, no write access to shared state, and no network path to systems that matter. Permissions and sandboxing are complementary: permission rules decide what the agent attempts, the sandbox enforces what its processes can reach, even if a prompt injection slips past the model's decision-making. The narrower and better-described each tool is, the less the agent attempts in the first place. See AI agent tool-calling patterns for least-privilege tool design.
Layer 4: Tamper-evident audit logs and idempotency
If something goes wrong, the audit log is the only artifact that tells you what the agent did, why, and who approved it. NIST AI RMF MANAGE 4.1 requires post-deployment monitoring plans that include mechanisms for appeal and override, incident response, and recovery, all of which depend on a trustworthy log.
"Trustworthy" here means tamper-evident, not physically unmodifiable. The standard technique is hash chaining: each log event embeds a cryptographic hash of the previous event, so any change, insertion, or deletion breaks the chain and becomes visible to a verifier. You don't need a blockchain — you need an append-only store and a hash field. A minimal event record looks like this:
{
"ts": "2026-06-28T14:03:11Z",
"agent_run_id": "run_8f2a",
"tool": "payments.charge",
"args_hash": "sha256:9c1f…",
"tier": "human_approval",
"approver": "alice@example.com",
"decision": "approved",
"idempotency_key": "run_8f2a:payments.charge:inv_551",
"prev_hash": "sha256:4b07…"
}
That idempotency_key field is the other half of safety. An operation is idempotent if performing it multiple times has the same effect as performing it once, and idempotency keys are unique identifiers that link related requests so retries — from clients, load balancers, or message brokers — do not cause duplicate side effects. This matters enormously for agents, which retry constantly. Stripe supports (and strongly recommends) idempotency keys on its API so requests are safely retryable without performing the same operation twice. The deeper principle is that in distributed systems "exactly-once" is generally achieved as at-least-once delivery plus idempotent processing. That is exactly why AWS builds its services around idempotent APIs to "deliver the benefits of automated retry policies" while still honoring an "at most once" commitment. Require an idempotency key on every agent tool call that mutates state, and a retried "charge the customer" becomes a no-op instead of a double charge.
How the four layers compose
The four layers compose into a single decision path. Map every tool to a tier (NIST Map). Enforce tiers below the model with a fail-closed default (OWASP complete mediation). Route irreversible actions to a human and add denial-based abort backstops (Anthropic checkpoints + NIST Manage 2.4). Run open-ended code only inside a sandbox. Write every decision to a hash-chained, idempotency-keyed log (NIST Manage 4.1). None of these layers is exotic, and skipping any one of them is where the incidents come from.
A realistic 30-day rollout: week 1, inventory and classify your tools; week 2, ship the deny→ask→allow enforcement layer with read-only defaults; week 3, add the human-approval queue for tier-3 actions plus iteration caps; week 4, turn on hash-chained logging and idempotency keys. You can run an agent in production on day 1, as long as it only touches tier-1 tools until the rest is in place. Once the guardrails hold, the next discipline is proving they keep holding: see how to evaluate AI agents for the regression-testing side of the same problem.
Tracing the claims to their sources
The permission specifics (the deny → ask → allow ordering and read-only-by-default table) come from the Claude Code permissions docs; the fail-closed default is quoted from the Claude Code security docs; the --dangerously-skip-permissions/bypassPermissions sandbox guidance is quoted from the Claude Code permission-modes docs; and the Auto Mode escalation at 3 consecutive or 20 total denials comes from the Auto Mode write-up, all listed in Sources. The Excessive Agency framing, its three root causes, and the eight prevention strategies in the table are drawn from the OWASP LLM06:2025 page. MANAGE 2.4 (the kill-switch basis) and MANAGE 4.1 (post-deployment monitoring) are quoted from the NIST AI RMF Playbook. The "pause for human feedback at checkpoints" wording is from Anthropic's Building Effective Agents; the "before high-stakes decisions" framing and the subscription-cancellation approval example are from Anthropic's safe-and-trustworthy-agents framework. The "irreversible / payment / delete / email" generalization is my own. The idempotency-makes-retries-safe claim traces to the Stripe and AWS pages cited inline; the "exactly-once = at-least-once + idempotency" framing is the standard distributed-systems formulation, not a verbatim AWS quote. The one thing here with a shelf life is the exact 3/20 denial threshold, which is a product behavior Anthropic can retune. The rest is framework text that moves slowly.
Sources
- OWASP LLM06:2025 Excessive Agency
- NIST AI Risk Management Framework (AI RMF 1.0)
- NIST AI RMF Playbook — Manage function (MANAGE 2.4, 4.1)
- Anthropic — Building Effective Agents
- Anthropic — Our framework for developing safe and trustworthy agents
- Claude Code — Configure permissions (deny → ask → allow order, read-only by default)
- Claude Code — Security (fail-closed matching)
- Claude Code — Choose a permission mode (bypassPermissions /
--dangerously-skip-permissions) - Anthropic Engineering — Claude Code Auto Mode
- AWS Builders' Library — Making retries safe with idempotent APIs
- Stripe — Designing robust and predictable APIs with idempotency

Top comments (0)