Home / Blog / prompt injection

Prompt Injection Explained: Securing AI Agents

October 13, 20266 min readBy Roopesh LR
Can your AI agent be hijacked?

Prompt injection is the number one security problem for anyone building AI agents, and most builders only learn about it after something leaks. If your agent reads emails, web pages, or documents, someone else can write instructions into them.

What Is Prompt Injection?

Prompt injection is an attack where untrusted text tricks a large language model into following instructions the developer never intended. The model has no hard boundary between "instructions from my builder" and "data I am processing." It all arrives as tokens.

Compare it to SQL injection. In SQL injection, user input gets interpreted as code. Here, user or third-party content gets interpreted as instructions. The difference: SQL has a real fix (parameterized queries). LLMs do not have a perfect equivalent yet.

Direct vs. indirect injection

Why Prompt Injection Gets Worse With Agents

A chatbot that only talks can embarrass you. An agent that acts can cost you money and data. Security researcher Simon Willison describes the risky combination as the "lethal trifecta": an agent that has access to private data, is exposed to untrusted content, and can communicate externally. Put all three together and an attacker can instruct the agent to read your private data and send it out.

Concrete examples of how this plays out:

Every new tool and every new data source widens the attack surface. More autonomy means more damage when it goes wrong.

How to Prevent Prompt Injection in AI Agents

No single filter solves it. Treat prompt injection prevention as layered defense, the same way you treat any untrusted input.

1. Break the lethal trifecta

This is the most reliable move. For each agent, ask which of the three legs you can remove. An agent reading untrusted web pages should not also hold your customer database credentials. An agent with private data access should not be able to make arbitrary outbound requests.

2. Apply least privilege

Give the agent the minimum scopes it needs. Read-only tokens where possible. Separate API keys per agent. Short-lived credentials. If an injection succeeds, the blast radius stays small.

3. Require human approval for risky actions

Sending email, moving money, deleting data, deploying code, and changing permissions should need a human click. Show the user exactly what will happen, not a vague summary written by the model that may itself be compromised.

4. Separate and label untrusted content

Wrap external content in clear delimiters and tell the model it is data, not instructions. This helps, but do not rely on it. Models can still be talked out of it. Think of it as reducing the odds, not closing the hole.

5. Use a quarantined model pattern

Let one model process untrusted content with no tools and no access to secrets, and return only structured, validated output (for example a JSON object with fixed fields). A second, privileged model or plain code acts on that output. The untrusted text never reaches the model that holds the keys.

6. Control outputs and egress

Block or allowlist outbound domains. Strip or refuse markdown images and links pointing to unknown hosts, a common data exfiltration channel. Validate tool arguments with code before executing them.

Testing and Monitoring Your Agent

Assume your first design is vulnerable and go looking for the hole.

The Mindset That Actually Works

Do not ask "can I stop the model from ever being fooled?" Ask "if the model is fooled, what is the worst it can do?" Design so the answer is "not much."

Models keep getting more resistant to injection, and vendors keep shipping better defenses. But resistant is not immune. Build as if the model will eventually follow a malicious instruction, because sooner or later one will.

The builders who ship agents safely are not the ones with the cleverest system prompt. They are the ones who limit access, gate dangerous actions, and treat every piece of outside text as hostile until proven otherwise.

Go deeper

AI CEO — How AI Will Replace the Tech Industry

This is the surface. The full argument — with the data, the case studies, and the playbook — is in the book. Roopesh LR's AI CEO is available to learn more.

Get the book →
prompt injection attacksindirect prompt injectionprevent prompt injectionAI agent securityLLM securitylethal trifectaAI agent vulnerabilities
© 2026 Roopesh LR · AI CEOAll articles · aiceo.me