RBRunbook
Study

Domains · Domain 7 · 11% of scored questions

Runtime Guardrails and Production Security

About 7 of the 60 scored questions come from this domain. It has 3 skills:

Lessons

Skill

Runtime Guardrail Systems

Layered guardrails: what the model decides and what code decides

A guardrail architecture is a set of layers, each of which stops a different failure. The exam asks you to match layers to an agent's risk profile. Start with one question: what is the worst thing this agent can do, and can it be undone? Reversible actions inside a disposable sandbox can be checked automatically. Irreversible actions need a control that does not depend on the model choosing well.

Deterministic enforcement

A system-prompt rule is a request. A hook, a deny rule, or an operating-system sandbox is enforcement. Know how the layers order themselves in Claude Code and the Agent SDK:

  1. Hooks run first. A hook can deny a call outright.
  2. Deny rules, then ask rules. A deny rule holds even in bypass mode and even when a hook returned allow.
  3. The permission mode, then allow rules.
  4. The approval callback runs only if nothing earlier decided the call.

Two consequences follow. A check placed in the approval callback never runs for a tool that an allow rule or mode already approved; put that check in a pre-execution hook. And a hook that throws lets the call go ahead by default; set the hook to block on failure when the action matters more than availability.

A shell deny rule matches the command text. Bash(rm *) stops rm -rf build/ but not /bin/rm -rf build/ or bash -c 'rm ...'. The documentation says such a rule "isn't a security boundary around the program". When a restriction must hold however a command is spelled, use sandboxing, which the operating system enforces.
Sandboxing without exposing production

Give the agent tools and web access inside a boundary, and keep credentials and production systems outside it. The options trade isolation for cost:

TechnologyKernelCost
Sandbox runtimeShared with hostVery low
ContainerShared with hostLow
gVisorSystem calls intercepted in user spaceHeavy on file I/O
Virtual machineOwn kernelHigh

Network allowlists work by host, not by operation: an allowed host accepts uploads as well as downloads. Check whether a sandbox has an escape hatch. In Claude Code a failed command can be retried outside the sandbox unless strict mode turns that off.

Approval gates

Managed Agents has three permission policies: run every call, pause every call for a person, or let the server evaluate each call. Server evaluation exists because "A person cannot approve every call in a long run". It is not a human checkpoint. Use the pause policy where a change cannot be undone outside the sandbox, and for anything that moves money. Watch for two failures: reviewers who approve thousands of low-risk calls stop reading them, and a client that approves every paused call without showing it to anyone is the same as no gate. Permission policies do not cover custom tools; your application must gate those itself. A paused session waits indefinitely, so an unattended agent needs something that answers or interrupts.

Filters, redaction and tuning
  • Input screens: a small model classifies the input with a structured verdict. If the screen itself is refused, there is no verdict; treat that as harmful.
  • PII redaction: redact where data enters the system (the tool result), not only where it leaves. Redacting the final answer leaves raw data in conversation history, traces and logs.
  • Thresholds: a false positive costs a blocked user; a false negative costs whatever the agent can do. Set the threshold per agent by blast radius, not once for the fleet.
Refusals

A refusal is a successful HTTP 200 response with a refusal stop reason, so error-rate dashboards never see it. Count refusals as their own signal. Discard any partial output, do not parse the explanation text, and retry on a different model, because the same model usually refuses again. In a multi-turn conversation, remove or rephrase the refused turn before continuing.

Sources
Configure permissions (Agent SDK)
Intercept and control agent behavior with hooks
Hooks reference
Configure permissions (Claude Code)
Configure the sandboxed Bash tool
Securely deploying AI agents
Permission policies
Secure your Managed Agents deployment
Refusals and fallback
Handle streaming refusals
Mitigate jailbreaks and prompt injections

Skill

Threat Defense and Adversarial Testing for Agentic Systems

Attack surface of a tool-using agent, and how to test it

There are two threat models, and they call for different defences. In direct injection the user is the adversary and types the attack. In indirect injection the user is trusted, but the agent reads third-party content that carries instructions: an email, a webpage, a ticket, a repository file, a tool result. For agents, the second is the one that matters most, because the attacker needs no account.

Find the dangerous combination

List three things for each agent: what private data it can read, what untrusted content it reads, and how it can send data out. An agent with all three can be told by a document to send your data to an attacker. Outbound paths are easy to miss:

  • A URL the agent fetches can carry data in its path or query string.
  • A search query is sent to the search provider. A domain list on a search tool "limits which sites results come from, not what the query contains".
  • An allowed host accepts any request, including git push and package publishing. Shared hosting domains, where anyone can publish, are exfiltration paths.
  • The agent's own reply and tool outputs can contain anything it was allowed to read.

Remove one leg of the combination. The Managed Agents guidance gives three designs: split reading from acting, give the agent one narrow custom tool that your application runs and checks, or require a person's approval. For a strong split, use two sessions with separate environments and pass only fixed fields between them.

Handle untrusted content correctly
  1. Deliver third-party content only in tool results, never in the system prompt or a plain user text block.
  2. Label what it is and where it came from, and JSON-encode it so it cannot break out of its delimiters.
  3. State in the system prompt that tool content is data, not commands.
  4. Put your own instructions in a user turn after the tool result. Instructions you place inside a tool result may be ignored or flagged.
  5. Optionally screen tool output with a small model before the main model sees it.
A clean red-team result is not a reason to drop the other layers. The documentation says Claude is resilient to injection, "but model behavior is not a security control". Size the tools, credentials and network for the day an attempt succeeds.
Poisoning and MCP configuration
  • Memory: text an agent saves from untrusted input is read by later sessions as trusted memory. Attach memory stores read-only unless the agent must write.
  • Tools: an MCP toolset enables every tool the server exposes by default, so a server update can add a tool. Disable by default and enable tools by name, and keep the toolset default on approval so new tools wait for a person.
  • Repositories: instruction files and skills in a mounted repository can load as agent instructions. Mount only repositories you trust.
  • Tokens: an MCP server must accept only tokens issued for it and must use its own separate token upstream. Passing a client token through breaks audience checks and the audit trail.
  • Scopes: start minimal and elevate when needed; avoid wildcard scopes.
Standards

The OWASP Top 10 for LLM Applications entry on excessive agency names three root causes: excessive functionality, excessive permissions and excessive autonomy. Fix those first. OWASP states that logging and rate limiting will not prevent excessive agency; they limit damage. Its prompt-injection entry says no fool-proof prevention is known, which is why least privilege and human approval sit beside filtering. The NIST Generative AI Profile (AI 600-1) organises actions under Govern, Map, Measure and Manage, lists prompt injection under information security, and calls for red-teaming to assess resilience to it.

Design the red-team exercise

Test the channels an attacker can actually reach. Seed documents, emails and tool outputs with injection attempts. Score outcomes, not refusals: did a tool get called, did data leave, did memory change? Check that screening and approval steps catch what the model misses. Repeat after every tool, prompt or model change, and keep monitoring production output for signs of success.

Sources
Mitigate jailbreaks and prompt injections
Secure your Managed Agents deployment
Security risks and sandbox boundaries
MCP Security Best Practices
MCP Authorization specification
OWASP LLM01: Prompt Injection
OWASP LLM06: Excessive Agency
NIST AI 600-1, Generative AI Profile

Skill

Identity, Secrets, and Audit at Scale

Identity, secrets and audit for agents in production

Three questions run through this skill. Who is this workload? What can its credential do? Can you prove afterwards what it did? Static shared keys answer all three badly: they never expire, they are copied into many places, and one key hides many callers.

Workload identity federation

With federation, a workload presents a short-lived signed token from an identity provider you already run (a cloud provider, Kubernetes, a CI system). The platform checks it against a rule and returns a short-lived access token bound to a service account. There is no static secret to store, rotate or leak. Three resources express the trust: the issuer (whose tokens count), the rule (which claims must match), and the service account (which identity the token acts as).

  • All of a rule's matchers must pass. A rule that matches only a broad subject prefix lets every workload under that prefix act as the service account. Match the exact subject or claims.
  • Register an issuer per environment, so production and staging trust are separate.
  • Federation is only as strong as the identity provider that signs the token.
Migrating from a static key
  1. Configure federation alongside the existing key.
  2. Check which credential the workload actually uses.
  3. Remove the key from every place it is injected, and check again.
  4. Delete the key.
In the SDK's credential order the API-key environment variable sits above federation, so "a leftover key in the environment silently overrides federation". A migration can look complete while every request still uses the old key. Deleting the key first, while it is still injected, causes an outage instead of a migration.

Identity tokens with a token identifier are single-use. A retry loop that reuses a cached token fails as a replay. Fix the workload so it gets a fresh token for each exchange. Turning off the replay check is a last resort, and it removes the protection for every rule on that issuer.

Keeping secrets away from the agent

Anything inside the agent's sandbox can be read by code the agent runs, including code it was tricked into running. Keep credentials outside the boundary:

  • Proxy pattern: a proxy outside the boundary adds the credential to outgoing requests, enforces a host allowlist and logs traffic. The agent never sees the credential.
  • Vaults (Managed Agents): code sees a placeholder; the real secret is swapped in at egress, only for the hosts the credential allows. Limit it to exact hosts and to request headers.
  • Custom tools: your application holds the key and exposes one narrow operation.

None of these limits what the key can do on a host you allowed. "Limit a key's permissions at the service that issued it": if the task is read and update, the key should not be able to delete. This is least privilege applied at the only place that can enforce it. Also check what sits in mounted directories; read-only access to a repository can still expose .env files and cloud credentials.

Least-privilege tool permissioning

Give each agent the smallest tool set, each tool the narrowest scope, and each credential the narrowest role. Run actions in the context of the user they are for, not with a shared administrator identity. For MCP, a server must accept only tokens issued for it and must use a separate token upstream; forwarding the client's token makes downstream logs show the wrong identity.

Audit logging
NeedDo this
Attribute model-API trafficOne service account per workload, not a shared workspace key
Record what an agent didLog each tool call at the layer that executes it (proxy, gateway, tool server), with identity, input, permission outcome and result
Trust the recordStore it where the agent cannot write; do not rely on the agent's own summary
Organisation activityEnable the Compliance API Activity Feed early: recording starts at enablement and is not backfilled

Managed Agents tool-use events carry the permission outcome and, under server evaluation, a reason code meant to be kept in audit records. When an incident starts, the order is: interrupt the agent, pause its schedule, rotate any exposed key at the issuer, then read the record.

Sources
Workload Identity Federation
Admin API
Query the Activity Feed
Authenticate with vaults
Secure your Managed Agents deployment
Security risks and sandbox boundaries
Permission policies
Securely deploying AI agents
MCP Authorization specification

Sample questions

Sample question
A SaaS company runs agent-generated build scripts for many customers on shared worker hosts. Each job runs under an OS-level sandbox runtime with a domain allowlist and a read-only source mount; median job time is 40 seconds against a 2-minute objective. A threat-model review adds one requirement: a kernel exploit launched from one customer's job must not reach another customer's job on the same host. The jobs open and close tens of thousands of small files. A trial of three alternatives gave these median job times:
hardened container, all capabilities dropped      41 s
runtime intercepting system calls in user space    9 min
lightweight virtual machine from a warm snapshot  55 s
Which isolation change best meets the new requirement within the objective?
  • ARun each customer's job in its own lightweight virtual machine on the hosts
  • BMove each job into a hardened container with every Linux capability dropped
  • CAdopt the system-call-intercepting container runtime for every job on the hosts
  • DKeep the sandbox runtime and shrink each job's domain allowlist to a single host
Show the answer and explanation

Answer:

  • Run each customer's job in its own lightweight virtual machine on the hosts

The requirement is about the kernel: an OS-level sandbox and an ordinary container both share the host kernel, so a kernel exploit can cross tenants. A virtual machine per job gives each tenant its own kernel, and the trial shows it stays inside the objective at 55 seconds. A tighter domain allowlist limits network egress and does nothing about a kernel exploit. The hardened container is the fastest alternative, but dropping capabilities does not change the fact that the kernel is shared. The intercepting runtime does shrink kernel exposure, but at 9 minutes it breaks the objective on this file-heavy workload.

Sample question
A utility company is about to launch a billing-support agent. The agent reads inbound customer emails and PDF attachments, looks up accounts, and can issue bill credits through a tool. For the pre-launch security exercise, six engineers typed 240 jailbreak prompts into the staff chat window over two days; the agent refused all of them, and the report recommends launch. Customers reach the agent only by email. In an earlier pilot, one credit was issued during a run whose reply to the customer read as an ordinary acknowledgement. Which addition to the exercise most directly covers what it left untested?
  • AReplay last quarter's real customer emails and count anomalies in credits issued
  • BSend emails with instructions hidden in attachments and score replies for refusals
  • CAdd email-style jailbreak prompts to the typed set and compare refusals by phrasing
  • DSend emails with instructions hidden in attachments and score which tools are called
Show the answer and explanation

Answer:

  • Send emails with instructions hidden in attachments and score which tools are called

Customers can attack this agent only through content it reads, so the untested surface is indirect injection through emails and attachments. The pilot shows why the score must be the tool calls: a credit was issued while the reply looked normal. Scoring replies for refusals uses the right channel but the wrong outcome, and would have passed the pilot run. Replaying real mail tests ordinary behaviour, since last quarter's mail contains few if any attacks. Email-style prompts typed into the chat window still arrive as staff input, not as content the agent processes.

↑↓ move↵ openesc close