A team should secure a Claude application or agent through independent layers that assume another layer can fail. Classify and minimize data before it reaches Claude; authenticate the caller and authorize the requested task; keep API keys and other credentials in controlled secret systems; isolate untrusted input from application instructions; validate outputs and proposed actions; restrict execution with least-privilege permissions, sandboxing, deterministic command hooks, and explicit approvals; then monitor the complete path and prepare an incident response.

No prompt, hook, permission file, or sandbox is sufficient by itself. Prompts guide model behavior but do not enforce identity. Command hooks can run deterministic checks at supported events but can contain defects or be scoped incorrectly; prompt and agent hooks use a model for judgment. A sandbox reduces operating-system and network reach but does not decide whether exposed data is appropriate. Security comes from overlapping trust boundaries, application-enforced policy, observable decisions, and recovery when prevention fails.

Security Architecture: Protect Data, Decisions, and Effects

A Claude system crosses several trust boundaries. A user or upstream service supplies a request; the application loads data and builds model context; the Claude API returns content or a capability request; application code interprets that result; tools, hooks, or external systems may cause effects. Each transition needs a distinct security decision.

BoundaryPrimary questionLayered controlsEvidence to retain
Caller to applicationWho is asking, and may they request this task?Authentication, authorization, rate controls, tenant isolationPrincipal, policy decision, request correlation
Application to model contextWhich data and instructions may be sent?Data classification, minimization, redaction, trust labels, retention policySelected sources, classification, policy version
Model response to applicationIs the result complete, valid, and safe to use?Structural and semantic validation, output policy, human reviewCompletion state, validation outcome, reviewer action
Proposed action to executorMay this action occur with these arguments and effects?Permission rules, approval, tool broker, sandbox, deterministic command hookAction identity, decision, approver, execution result
Runtime to external systemsWhat resources may the process access?Short-lived identity, network and file restrictions, least privilegeCredential identity, target, audit event
Operations and incident responseCan the team detect and contain failure?Monitoring, alerting, revocation, isolation, rollback, investigationTimeline, affected scope, containment and recovery record

The table is a security architecture synthesis, not a vendor-mandated deployment topology. A small service may implement several controls in one process, but their responsibilities and evidence should remain distinguishable.

Establish Data Privacy and Retention Boundaries

Begin with the data, not the model. Identify which content is public, internal, confidential, regulated, or prohibited; who owns it; why the task needs it; where it may be processed; and how long each system may retain it. Personally identifiable information (PII), credentials, customer records, source code, and tool results can carry different obligations.

The current API and data retention documentation defines Anthropic's current service behavior and available policy context. Verify it for the exact service, account, feature, and deployment path in use. Do not turn a retention statement verified on 2026-08-28 into a permanent promise or assume that application logs, caches, queues, backups, and external tools inherit the same behavior.

Minimize data before context assembly

For every field considered for a request, ask:

  1. Is it necessary for the model task?
  2. Is the caller authorized to use it for this purpose?
  3. Can a less sensitive representation work?
  4. Does the destination and feature support the required policy?
  5. Where else will the value appear—in logs, traces, caches, tool calls, or review interfaces?
  6. What deletion, correction, or retention path applies?

Remove unnecessary fields before prompt construction. Redaction after a response cannot undo disclosure in the request. Use application-owned identifiers where possible instead of sending complete records, and retrieve sensitive source data only inside the narrow boundary that needs it.

Prevent cross-user and cross-tenant leakage

Context, memory, cache keys, session identifiers, retrieval filters, and tool credentials must preserve the same user and tenant boundary as the owning system. Never select memory or records only by semantic similarity. Include authorization and scope in the retrieval decision, and treat model-generated references as untrusted until resolved against an authorized source.

Separate Authentication, Authorization, and Secret Management

Authentication establishes an identity. Authorization decides what that identity may do. A credential supplies proof to a service. These concepts must not be delegated to model judgment.

The Claude API authentication documentation defines the current authentication contract. Keep Claude API keys and other credentials out of source code, prompts, client-side applications, CLAUDE.md, settings files intended for sharing, plugin bundles, model context, and ordinary logs.

Manage secrets through a lifecycle

A defensible secret lifecycle includes:

  • controlled creation through an approved identity or secret-management system;
  • the narrowest scope and environment reach available;
  • secure delivery to the server-side workload that needs it;
  • masking in logs, errors, traces, and support artifacts;
  • rotation and revocation procedures with named owners;
  • monitoring for unusual use and failed access; and
  • prompt containment and incident response when exposure is suspected.

Prefer workload identity or short-lived credentials where the destination and environment support them. Where a long-lived API key is required, restrict who and what can retrieve it, separate environments, and design rotation before deployment.

Authorize the application task separately

Possession of a Claude API credential authorizes access to the configured service account; it does not establish that an end user may access a customer record or execute a business operation. The application must evaluate the authenticated caller, tenant, resource, purpose, and requested effect before assembling context or exposing a tool.

Do not place hidden access-control lists in a prompt and ask the model to enforce them. A model can help explain a policy, but deterministic code or a policy service must make the authorization decision.

Design for Prompt Injection and Jailbreak Attempts

Prompt injection occurs when untrusted content attempts to redirect model behavior, reveal data, or trigger an unintended action. A jailbreak attempts to bypass intended behavioral constraints. Anthropic's current prompt-injection and jailbreak mitigation guidance recommends layered defenses.

Preserve trust labels through the pipeline

User messages, retrieved documents, web pages, email, tool output, and uploaded files can all contain instruction-like text. Mark their source and trust level before serialization. Delimit or label them clearly and tell Claude to treat them as data for the current task, but do not call that separation a security boundary.

The application should also:

  • exclude data and tools the task does not need;
  • constrain the task and output expectation;
  • validate output against application rules;
  • require approval before consequential actions;
  • isolate execution and restrict network or file reach;
  • monitor suspicious instruction patterns and policy failures; and
  • test adversarial and indirect-injection cases relevant to the system.

An attacker does not need the model to reveal a system prompt to cause harm. Redirecting a tool, exfiltrating retrieved data, or persuading the workflow to act outside the user's authority can be sufficient. Protect the effect boundary, not only prompt text.

Treat model output as untrusted input

A fluent response, a schema-shaped object, or a proposed command can still be wrong or maliciously influenced. Apply structural validation, semantic checks, destination-aware escaping, resource authorization, and business rules before use. Never execute generated code, shell text, database statements, URLs, or tool arguments solely because the model produced them.

Layer Guardrails Around the Model

A guardrail is a control that constrains, detects, or responds to unsafe or disallowed behavior. Use guardrails at several stages:

  1. Before the request: identity, authorization, data minimization, content classification, task allowlists, and rate controls.
  2. Inside request construction: clear instructions, trust-zone separation, approved context, and minimal tool exposure.
  3. After the response: completion checks, schema and semantic validation, content policy, citation or evidence checks, and human review.
  4. Before an effect: tool permission, argument validation, resource authorization, approval, and sandbox policy.
  5. After execution: result validation, audit logging, anomaly detection, revocation, and incident handling.

Model-side instructions are one layer in the second stage. They can improve behavior but cannot replace the other stages. High-impact use cases should also have qualified human oversight and organization-specific policy. This article provides technical architecture, not legal, regulatory, or compliance advice.

Use Claude Code Controls at Their Correct Boundaries

The Claude Code security documentation describes current product security principles and controls. Claude Code operates in a developer environment where files, commands, credentials, repositories, and network services may be reachable. Treat it as an active principal with bounded capabilities, not as a text editor.

Permissions decide whether a tool request may proceed

The current permissions documentation supports rules that allow, deny, or ask for approval for tool actions. Start from least privilege. Allow only stable low-risk actions required by the workflow, deny prohibited reach, and keep sensitive or unusual actions behind explicit approval.

Place organization requirements in the highest supported managed scope. Project settings can express reviewed repository needs but should not weaken managed policy. Instructions in CLAUDE.md or a Skill describe how work should be performed; permissions control whether a requested tool action may proceed.

Sandboxing reduces execution reach

The sandboxing documentation describes current file-system and network isolation controls. Claude Code's built-in sandbox provides operating-system-level enforcement for Bash commands and their child processes only. The built-in Read, Edit, and Write tools use the permission system directly rather than running through the sandbox; other tools and execution surfaces operate under their own permission and isolation boundaries. Configure each boundary to the task's actual needs, and test denied and allowed paths.

Sandboxing is not a data-classification engine, identity provider, output validator, or universal containment guarantee. A process can still misuse data and resources legitimately exposed inside the sandbox. Keep secrets and sensitive files outside reach when they are unnecessary, and pair sandboxing with permissions, approval, monitoring, and host or container controls.

Command hooks provide deterministic lifecycle controls

The Claude Code hooks guide distinguishes hook types. A command hook runs a shell command at a supported lifecycle event and provides deterministic control. A prompt hook uses a single model turn to evaluate a condition, while an agent hook performs multi-turn verification with tool access. Agent hooks are experimental and may change; the current documentation recommends command hooks for production workflows.

A command hook can, for example, block a prohibited path, require an approved precondition, format a changed file, or record an audit signal. Prompt and agent hooks can support judgments that are difficult to express as deterministic rules, but their model-driven decisions must not be represented as deterministic enforcement.

Command hooks need the same engineering discipline as other executable controls:

  • validate untrusted event data;
  • avoid unsafe shell construction;
  • run with minimal credentials and resource access;
  • define timeout, failure, and bypass behavior;
  • log decisions without exposing secrets;
  • test every relevant event and error path; and
  • version and review changes.

A hook protects only the events and paths it actually receives. It can fail, be misconfigured, or be absent from another execution surface. Keep the authoritative policy in an enforceable control layer. Use command hooks as one deterministic enforcement or evidence mechanism; treat prompt and agent hooks as model-driven judgments, with the additional change risk that accompanies experimental agent hooks.

Require Approval at Consequential Boundaries

Approval should occur immediately before the decision it governs and include enough context for a meaningful choice. “Allow tool?” is weaker than a review showing the action, target, arguments, data scope, expected effect, reversibility, and requesting identity.

Use approval for actions such as changing production state, sending external communications, modifying access, spending money, publishing content, deleting data, or expanding tool reach when the organization's risk policy requires it. Approval is not a blanket transfer of responsibility: validate that the approved action executed as described and record its result.

Avoid approval fatigue. If users routinely approve opaque or repeated prompts, redesign the tool scope, reduce permissions, batch truly equivalent low-risk actions, or create a deterministic allowlist. Never eliminate a required approval merely to improve automation throughput.

Detailed tool definitions, argument schemas, execution loops, and tool-result handling belong in Implementing Claude Tools with Safe Execution and Approval Patterns. Model Context Protocol (MCP) server authorization has its own host, client, server, transport, and resource boundaries and is handled separately.

Monitor the Complete Security Decision Chain

Monitoring should reconstruct what was requested, which policy and configuration applied, what data sources were selected, what model and tool path ran, which approval occurred, and what external effect resulted. Retain only the evidence permitted by privacy and security policy.

Useful security signals include:

  • failed authentication and authorization decisions;
  • unusual key use, environment changes, or credential errors;
  • prompt-injection and jailbreak indicators;
  • requests for denied tools, files, networks, or resources;
  • hook failures or bypass attempts;
  • sandbox violations;
  • repeated approval requests or unexpected approval rates;
  • anomalous data retrieval or output volume;
  • validation failures and unsafe-action blocks; and
  • changes in plugin, prompt, model, hook, permission, or policy versions.

Metrics require response plans. Assign owners and thresholds, and distinguish a user error from a policy defect, compromised credential, malicious input, unsafe tool design, or control failure.

Prepare an Incident Response

An incident plan should exist before credentials, sensitive data, or external actions enter the system. A proportional response can include:

  1. contain the affected session, tool, workload, credential, plugin, or network path;
  2. revoke or rotate exposed secrets and invalidate active access where supported;
  3. preserve authorized logs, configuration versions, request identifiers, approval records, and affected resource evidence;
  4. identify which users, tenants, data, actions, and downstream systems were in scope;
  5. correct the failed trust boundary and test the containment;
  6. restore service through a reviewed configuration or clean credential path; and
  7. document lessons, control changes, and required notification through the organization's process.

Do not copy raw sensitive prompts and responses into an unrestricted incident channel. Evidence handling must follow the same access and retention rules as the original data.

Common Security Architecture Mistakes

  • Using the system prompt as access control. Authentication and authorization belong in deterministic application controls.
  • Sending all available data “for context.” Minimize first and retrieve only authorized task-relevant records.
  • Keeping API keys in client code or shared configuration. Use a controlled secret-delivery path and design rotation.
  • Treating delimiters as prompt-injection prevention. They improve structure but do not enforce trust.
  • Assuming a valid output is safe. Validate meaning, destination, authority, and intended effect.
  • Granting a broad tool set for convenience. Least privilege and narrow execution boundaries reduce attack surface.
  • Treating a sandbox as complete containment. Pair it with identity, permissions, data controls, hooks, approval, and monitoring.
  • Treating hooks as infallible policy. Test their scope, inputs, errors, credentials, and bypass paths.
  • Requesting approval without useful context. The approver needs target, arguments, effect, and reversibility.
  • Collecting security logs without an owner. Detection without containment and recovery does not close the control loop.

Relevance to Claude Certified Developer – Foundations

The Claude Certified Developer – Foundations Exam Guide defines four Security and Safety skills: AI Application Security, Guardrails and Safe Deployment, Claude Hooks, and Identity, Secrets, and Key Management. Together they require developers to protect privacy and PII, address prompt injection and jailbreaks, prevent data leakage, apply layered guardrails and least privilege, use command hooks as deterministic controls, and govern credentials and approvals.

The durable engineering skill is to assign each risk to a control with an independent owner and failure mode. Identity protects the entry boundary; data policy controls context; validation protects consumption; permissions, hooks, sandboxing, and approvals constrain effects; monitoring and incident response close the operational loop.

Conclusion

Secure Claude applications assume that prompts can be manipulated, models can be wrong, credentials can leak, hooks can fail, permissions can be mis-scoped, and sandboxes can expose necessary resources. Layer data minimization, authentication, authorization, secret management, input isolation, output validation, least privilege, deterministic controls, approval, monitoring, and response so one failure does not become an uncontrolled effect.

Keep every control at the boundary it can actually enforce. Prompts guide; identity and policy authorize; permissions and sandboxes restrict; hooks check events; approvals govern consequential decisions; monitoring and incident response detect and contain. That separation produces a security architecture that is reviewable, testable, and adaptable as Claude product behavior and organizational requirements change.

Authoritative Sources