What you need to know
A guardrail is deterministic when it holds no matter what the model is told. Prompts are not guardrails; they are guidance.
The layers
| Layer | What it enforces | Example |
|---|---|---|
| Identity and access | What the agent can reach at all | Read-only database account; IAM role scoped to staging resources |
| Tool set | Which actions exist | Only the queries the report needs; no delete tool |
| Permission rules | Which tool calls run, ask or are denied | deny: ["Bash(git push --force:*)", "Edit(./infra/prod/**)"] |
| Hooks and tool code | Checks on each call's content | PreToolUse rejects DROP and TRUNCATE; tool validates refund amount |
| Sandboxing | Filesystem and network boundaries for every process | Network allowlist; writes only in /workspace |
| Platform controls | Rules the agent cannot change | Branch protection requiring human review on main |
| Logging | Evidence and detection | Every privileged action, allowed or blocked |
Least privilege
Give each agent, subagent and service only the permissions its task needs. It is the control that still holds when every other one fails: an injected instruction to delete records becomes a denied call and a log entry, not an incident. Protect the configuration too; whatever can widen an agent's permissions can remove the boundary.
Precedence
In Claude Code, deny beats ask beats allow, and managed settings outrank project and user settings. A specific deny blocks an action even when a broad allow exists.
Unrestricted modes
bypassPermissions (or any "no prompts" mode) is acceptable only in an isolated container or VM with no access to production systems, credentials or the open network. Prefer auto mode or pre-approved tools on real machines.
In the exam
Items describe an agent's permissions and a destructive action that must never happen, and ask which control enforces it. Pick identity scope, tool limits, deny rules, hooks or tool validation, sandboxing and platform controls, layered. Distractors rely on prompts, logging after the fact, larger models, shared admin accounts, or renaming sensitive folders.
Check your understanding
A database agent must never run DROP or TRUNCATE. What enforces it?
Show answer
Answer: D. The block runs before execution, whatever the instruction.
A project allows Bash(git:) and denies Bash(git push --force:). Which wins for a force push?
Show answer
Answer: A. Deny takes precedence over allow.
A hook blocks writes outside /workspace, but the agent can upload files with a network tool. What to add?
Show answer
Answer: B. Sandboxing covers paths that individual rules miss.
Apply it: Lock down Juniper's agent
Juniper's support agent connects to the orders database with an account that can read and write all tables. It can issue refunds, start returns and query inventory through the MCP server, which also exposes an "update_stock" tool meant for merchandising. Engineers run Claude Code in bypass mode on their laptops for speed.
- Scope the agent's identity and tools.
- Add deterministic checks for refunds and returns.
- Fix the Claude Code practice.
Done when: no prompt text is the only thing preventing a destructive action.
Show model answer
1. A database role with read access to orders and customers and write access only through the return and refund services (no direct table writes). Allow only the MCP server's read tools for the support agent (mcp__inventory__get_stock, mcp__inventory__get_product); update_stock is not in its allowed tools, and the MCP server checks the caller's identity before stock updates.
2. issue_refund validates amount against the order total and requires supervisor approval above $250 (tool code plus PreToolUse hook); start_return checks the return window; both log every call.
3. Disable bypassPermissions in managed settings; use auto mode or acceptEdits with deny rules for production config and secrets; keep bypass for disposable dev containers with no credentials.