Why AI Agents Are Vulnerable to Prompt Injection — and How to Secure Them at the Architecture Level
Classic security approaches stop working in AI systems because any text in the context window can influence model behavior. OWASP notes that all inputs carry the same trust weight, and the model cannot distinguish system instructions from external data. This architectural merger demands a fundamentally different approach to security. Andrey Biryukov proposes four architectural layers of defense: trust separation through typed context blocks, minimal tool privileges, memory and RAG-corpus control, and built-in human-in-the-loop. • Trust separation: every context block gets a label (SYSTEM, INTERNAL, UNTRUSTED) and is checked before an action is executed • Tool isolation: parameterized queries only, no shell commands, file and network restrictions • RAG monitoring: tracking document hashes, blocking low-trust sources, detecting anomalies in search results
AI-processed from Habr AI; edited by Hamidun News
In traditional software, architecture and security are clearly separated: there's a perimeter, authentication, input validation. In AI systems, this boundary blurs so much that classic approaches stop working.
The key problem: AI agents merge two things that were always kept apart — the control plane and the data plane. In a normal application, a user command is processed by deterministic code, and data can't rewrite the logic. In an LLM system, any text in the context window can potentially influence the model's behavior.
OWASP puts it this way: "All inputs carry the same trust weight, and the model cannot internally distinguish trusted instructions from untrusted data." This is an architectural shift that requires building security into the system from the ground up, not adding it as a filter on top.
Principle 1: Trust separation as an architectural primitive
Many architects place untrusted content, internal data, and system instructions in the same context window, assuming the model will sort it out on its own. That's a mistake. The solution is introducing an explicit trust level for every fragment, with enforced layer separation.
The system doesn't work with concatenated prompt strings — it works with typed context blocks. Each block gets provenance metadata and a trust level: system instructions are trusted, data from an internal database is internal, external content and RAG documents are untrusted. Tools check these labels before executing.
OWASP calls this "segregation of trust," and as of 2026 emphasizes that it's no longer just a best practice — it's an architectural requirement.
Principle 2: Tool isolation and least privilege
A dangerous architectural mistake is giving an LLM access to tools with excessive permissions. That could be a "read" tool that's actually able to delete documents, or a database connection with admin rights when all that's needed is SELECT. The solution: give each tool the minimum necessary set of permissions and an isolated execution context.
Instead of handing the model raw SQL queries, the system accepts structured parameters (table, filters, limit) and builds the parameterized query itself. This rules out an entire class of injection attacks. Avoid open-ended functionality like executing shell commands or arbitrary URL requests. Use granular tools with constraints: file tools that write only to a specific directory and only with a specific extension, email tools that send only to addresses on an approved allowlist.
Principle 3: Controlling memory and the RAG corpus
The RAG corpus is part of the attack surface — often a more dangerous one than the prompt itself. Research from WARP showed it's possible to inject "poisoned" documents into a search corpus so that, on trigger, RAG retrieves exactly those documents. The AgentPoison study succeeded in 82% of cases with a poisoning rate below 0.1% — a single malicious document per thousand can be enough.
Defense involves three layers: provenance control for every document, with metadata and content hashes; isolation of search results, flagged as untrusted; and drift monitoring — detecting when search starts returning documents it never returned before.
Principle 4: Human-in-the-loop as an architectural component
This isn't a UI feature with a confirmation button — it's a component built into the runtime. Actions are classified by risk level: LOW (read-only, internal data), MEDIUM (write to sandbox, internal notifications), HIGH (delete, external API calls, financial operations). HIGH-risk actions require confirmation, and the agent cannot bypass it.
Real-world incidents confirm the need: CVE-2025-32711 (EchoLeak) — a prompt injection in Microsoft Copilot with zero-click data exfiltration; CVE-2025-54135 and CVE-2025-54136 — remote code execution via prompt injection in the MCP implementation of Cursor IDE. All of these resulted from architectural mistakes, not model shortcomings.
This isn't a story about making the model safe. It's about designing security at the level of the system's architecture.
- Oct 27, 2026Qwen3.8 Tried to Upload a File to Alibaba's Cloud in Beijing From Inside Cohere's Sandbox
- Oct 26, 2026Synopsys Plans to Plug Chinese AI Models Into Chip Design in China
- Oct 26, 2026SpaceXAI Bundles Grok, Cursor and X Into a Single Subscription From $8 a Month
- Oct 26, 2026OpenAI Cuts 2026 Revenue Forecast to $50 Billion From $70 Billion
Key Questions Answered
What are the key details on Principle 1: Trust separation as an architectural primitive?
Many architects place untrusted content, internal data, and system instructions in the same context window, assuming the model will sort it out on its own. That's a mistake. The solution is introducing an explicit trust level for every fragment, with enforced layer separation. The system doesn't work with concatenated prompt strings — it works with typed context blocks. Each block gets provenance metadata and a trust level: system instructions are trusted, data from an internal database is internal, external content and RAG documents are untrusted. Tools check these labels
What are the key details on Principle 2: Tool isolation and least privilege?
A dangerous architectural mistake is giving an LLM access to tools with excessive permissions. That could be a "read" tool that's actually able to delete documents, or a database connection with admin rights when all that's needed is SELECT. The solution: give each tool the minimum necessary set of permissions and an isolated execution context. Instead of handing the model raw SQL queries, the system accepts structured parameters (table, filters, limit) and builds the parameterized query itself. This rules out an entire class of injection attacks. Avoid open-ended functiona
What are the key details on Principle 3: Controlling memory and the RAG corpus?
The RAG corpus is part of the attack surface — often a more dangerous one than the prompt itself. Research from WARP showed it's possible to inject "poisoned" documents into a search corpus so that, on trigger, RAG retrieves exactly those documents. The AgentPoison study succeeded in 82% of cases with a poisoning rate below 0.1% — a single malicious document per thousand can be enough. Defense involves three layers: provenance control for every document, with metadata and content hashes; isolation of search results, flagged as untrusted; and drift monitoring — detecting whe
Delegate Deep Research, Coding & Workflows to an AI Agent
Deploy autonomous multi-step execution with NomadNet Agent (agent.nomadnet.ai) — automated web research, data synthesis, code generation, and complex task orchestration.
The AI world, distilled — once a week
Seven stories that actually mattered, hand-picked. No noise, no reposts, no press releases.
Done! Check your inbox for a confirmation.