claudio.cool
CCDV-PLessons

CCDV-P · Runtime Guardrails and Production Security

Runtime guardrails, layers, hooks and keeping the irreversible outside the model

⏱ 3 min readDraft

An operations agent has a terminal and access to a small company’s database. One day, trying to “clean up test data”, it runs an unfiltered delete on a production table. The system prompt said “never delete production data”. The model isn’t malicious or “disobedient”: an instruction is a suggestion the model follows almost always, and almost always isn’t enough for the irreversible.

Guardrails matched to risk

A runtime guardrail is a control that acts while the agent runs. You design them in layers according to risk: what’s the worst the agent could do with its permissions?

Layer Function Example
Input filters classify or block before it reaches the agent injection-attempt detector, size limit
PII redactors remove personal data from context or output mask card and ID numbers before sending to the model or to a log
Output filters validate what the agent will return or execute valid schema, no secrets, no out-of-policy content
Hooks code that runs before or after each tool a PreToolUse that blocks dangerous commands
Isolation the agent runs where damage is bounded a sandboxed environment with no access to production
Approvals a person authorizes what crosses a threshold transfers, external sends, deployments
Audit a record of what it did who, what, when, with what result

The irreversible is enforced deterministically

Deterministic enforcement means the rule is applied by code outside the model, the same way every time, no matter what the model “decides”. For irreversible or high-impact actions (delete, pay, send externally, deploy), the rule doesn’t live only in the prompt:

  • Destructive-action prevention: a pre-execution hook that parses the command (in Claude Code, a PreToolUse hook exiting with code 2 blocks the call; in the Agent SDK, hooks and a permission callback play the same role) and rejects the dangerous even when written a new way. Better still, the agent lacks the permission: a read-only database role or one with a row limit.
  • Sandboxing: give the agent the terminal and web it needs without exposing production: network restricted to allowed domains, filesystem scoped to the project, test-environment credentials. Claude Code includes a mode with file and network isolation for commands; verify its scope in the documentation.
  • Approval gates: for actions that are allowed but deserve a person, with the detail of what will happen.

Refusals and safety fallbacks

When the model refuses a request, the system needs a defined path: a clear message, a safe alternative or a handoff to a person. You don’t retry in a loop or “rephrase until it accepts”, which is itself an attempt to evade a safeguard.

Tuning false positives and negatives

Every guardrail errs in two directions. A false positive blocks something legitimate and frustrates people (who end up looking for shortcuts); a false negative lets through what should have been stopped. You measure them with a labeled set of good and bad cases, tune the threshold to the cost of each error (for the irreversible, tolerate more friction) and review with production data. A filter nobody measures ends up switched off or useless.

The usual traps

  • A capitalized instruction in the prompt as the control for the irreversible.
  • Manual approval of every action, until approvals happen without reading.
  • A list of forbidden commands with every imaginable spelling instead of minimal permission.
  • Giving the agent the admin account and asking it “not to write”.
  • Rephrasing a refused request until it passes.

On the exam

For something irreversible, pick the control enforced outside the model (hook, permission, sandbox, approval). To balance legitimate blocks, tune the threshold with labeled data rather than switching the layer off.

Quick question

A practice exam question on this domain. It counts towards your progress.

A platform team uses Claude Code to help engineers maintain infrastructure repositories. The project CLAUDE.md states, in bold, that the agent must never run terraform destroy or apply against the production workspace. Last week, during a long session, the agent ran a production apply that deleted a managed database, because it interpreted a user request about "cleaning up unused resources" as permission.

The team wants a control that does not depend on the model remembering or interpreting a sentence correctly in every session, and that applies to every engineer's machine.

Which control is most appropriate?

Practise this domain in a practice exam →