Security protects AI systems and information from unauthorized manipulation, data tampering, and exploitation. In context-aware systems, it includes protecting the confidentiality and integrity of the sources assembled into a model’s context. section 9.1.2
Security differs from safety: security addresses unauthorized access and manipulation, while safety addresses harmful, toxic, or misleading outputs. The two meet in prompt injection, where a model treats untrusted data as an instruction. System directives, retrieved documents, tool payloads, and user messages all enter the model as tokens, rather than through a native privilege boundary. section 9.1.2
Prompt injection can enter through two routes:
- Direct injection places adversarial instructions in a user message, for example to override system directives or extract sensitive information. section 9.1.2
- Indirect injection embeds instructions in external data, such as a retrieved document, web page, or tool output, to hijack agent execution when the data enters context. section 9.1.2
A retrieved page as an attack surface
An agent fetching a web page may ingest an instruction embedded in the page alongside the information it requested. If the agent follows that instruction as authority rather than treating it as untrusted data, the payload can redirect execution. Tool permissions and approval thresholds limit what a redirected agent can do. section 9.1.2
Prompt delimiters and data-tagging instructions can reduce accidental misinterpretation, but prompts alone cannot enforce security boundaries. Defense in depth combines untrusted-span labeling and authority separation with least-privilege tool execution and guardrails. Authorization and data minimization also constrain which records, memories, and tool outputs enter context. section 9.1.2 section 9.5
Table 9.1 Safety and security controls mapped to context engineering stack components
| Stack component | Main risks | Typical controls |
User prompt and instructions |
Prompt injection, policy bypass, and prompt drift |
Input sanitization, approved templates, and versioned rollback |
External knowledge and retrieval |
Data poisoning, stale content, and unauthorized sources |
Source allowlists, document permissions, and freshness monitoring |
Memory and state |
Memory poisoning, unsafe carryover, and cross-user leakage |
Retention rules, memory eligibility policies, and session isolation |
Tools |
Unsafe actions, excessive authority, and parameter tampering |
Tool allowlists, least-privilege permissions, and approval thresholds |
Context management and orchestration |
Unsafe routing, context pollution, and failure propagation |
Routing policies, context isolation, and fallback paths |
Evaluation, observability, and operations |
Harmful output, unsupported claims, and unsafe rollout |
Output validation, citation checks, and release gates with rollback triggers |
Compare risks and controls across prompts, retrieval, memory, tools, and orchestration. section 9.1.2



































