CCDV-F Prep unofficial
← All skills

Security and Safety

Deterministic Guardrails and Least Privilege

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

What the exam tests

Whether you can make a destructive action impossible, not merely unlikely. Given an agent, its tools and a threat (a mistake or hostile instructions in content it reads), you choose layers that do not depend on the model agreeing: tool availability, permission rules and modes, hooks, OS or network isolation, and narrowly scoped credentials.

Key rules

Enforcement lives outside the model. System prompts and CLAUDE.md shape what Claude tries to do. Permission rules, modes and hooks are applied by Claude Code.

Rule order. Deny, then ask, then allow. Specificity does not matter, so an allow rule cannot carve an exception out of a deny. A bare deny such as Bash removes the tool from context; a scoped one such as Bash(rm *) blocks matching calls.

Agent SDK flow. Hooks, deny rules, ask rules, permission mode, allow rules, then canUseTool. A call approved early never reaches the callback. allowed_tools only pre-approves and does not constrain bypassPermissions. For a locked-down headless agent, pair it with dontAsk.

Hooks. A PreToolUse hook sees calls before they run and can inspect arguments. Its deny holds in every permission mode; its allow does not override deny or ask rules. When hooks disagree, the most restrictive decision wins.

  • Command hooks block with exit code 2, or exit 0 with a JSON deny. Exit 1 alone does not block.
  • A missing, crashing or timed-out command hook lets the call continue unless onFailure is "block".
  • An SDK callback that times out on PreToolUse blocks. One that throws lets the call proceed to the permission flow unless onFailure is set. One that catches its error and returns {} has not failed.
  • PostToolUse runs too late to prevent anything.
{
  "permissions": { "deny": ["Bash(git push *)"] },
  "hooks": {
    "PreToolUse": [
      { "matcher": "Bash",
        "hooks": [ { "type": "command",
                     "command": "node",
                     "args": ["${CLAUDE_PROJECT_DIR}/.claude/hooks/check.js"],
                     "onFailure": "block" } ] }
    ]
  }
}

Isolation. Bash rules match command text, so another path, wrapper or script can evade them. The sandbox restricts shell commands and their child processes at OS level, but not built-in file or web tools, hooks or local MCP servers. By default it still reads most of the machine and inherits environment variables. In bypassPermissions mode, hosts outside the allowed domains still connect unless strictAllowlist or the managed allowManagedDomainsOnly is on. Close the unsandboxed retry with allowUnsandboxedCommands: false. For one boundary around everything, use a container or VM.

Least privilege. Mount only what is needed, read-only where possible; restrict egress; keep credentials outside the boundary behind a proxy or custom tool that exposes only the needed operation.

Organization control. Managed settings carry rules users cannot override. Add allowManagedPermissionRulesOnly to ignore other rule sources and permissions.disableBypassPermissionsMode: "disable" to remove bypass mode.

Managed Agents (beta). Policies are always_allow, always_ask and auto. The agent toolset defaults to always_allow, MCP toolsets to always_ask. Policies do not cover custom tools: your application must gate them.

Traps

  • Treating a stronger prompt, or a model-based check, as a deterministic guarantee.
  • Expecting allowedTools to restrict an agent.
  • Putting the safety check in canUseTool while an allow rule or mode skips it.
  • Listing more command spellings instead of adding a boundary.
  • Assuming a broken policy hook fails closed.
  • Relying on the built-in critical-path rm check: it can miss commands and covers only rm and rmdir.

Decide quickly

SituationChoiceWhy
Tool is never neededBare deny ruleClaude never sees it
Headless agent with a fixed tool setAllow list plus dontAskAnything else that would prompt is denied
Block depends on argument valuesPreToolUse hookCustom logic, runs in every mode
Must hold for any script or spellingSandbox, container or VMOS-level boundary
Agent needs an authenticated serviceProxy or custom tool outside the boundarySecret never exposed
Human must approve a risky callAsk rule or always_askPauses even where other calls run freely
Policy for every developerManaged settings with locksLocal settings cannot loosen it

Sources