CertPrep
Domain 7 · Lesson 7.2 · 4 min read

Deterministic Guardrails and Least Privilege

Exam skillDeterministic Guardrails and Least Privilege

Applying guardrail layering, least privilege, and hooks as deterministic enforcement so that destructive actions cannot execute even under adversarial instruction.

Make destructive actions impossible rather than unlikely: give each agent the narrowest identity and tool set its task needs, enforce rules with permission rules, hooks and tool code, add OS-level sandboxing for paths rules do not cover, and run unrestricted modes only in isolated environments.

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

LayerWhat it enforcesExample
Identity and accessWhat the agent can reach at allRead-only database account; IAM role scoped to staging resources
Tool setWhich actions existOnly the queries the report needs; no delete tool
Permission rulesWhich tool calls run, ask or are denieddeny: ["Bash(git push --force:*)", "Edit(./infra/prod/**)"]
Hooks and tool codeChecks on each call's contentPreToolUse rejects DROP and TRUNCATE; tool validates refund amount
SandboxingFilesystem and network boundaries for every processNetwork allowlist; writes only in /workspace
Platform controlsRules the agent cannot changeBranch protection requiring human review on main
LoggingEvidence and detectionEvery 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

Question 1

A database agent must never run DROP or TRUNCATE. What enforces it?

Show answer

Answer: D. The block runs before execution, whatever the instruction.

Question 2

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.

Question 3

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

Exercise · about 20 minCase: Juniper Outdoor Co.

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.

  1. Scope the agent's identity and tools.
  2. Add deterministic checks for refunds and returns.
  3. Fix the Claude Code practice.
    Done when: no prompt text is the only thing preventing a destructive action.
Check your work
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.

Key termsGuardrailLeast privilege

Sources