# Indirect Prompt Injection

> The Indirect Prompt Injection is an attack where malicious instructions are hidden in external content that an AI model processes.

## What is indirect prompt injection?

The attack where instructions are hidden in web pages, documents, emails, issues or code comments that an agent reads while working. The user never sees them, but the agent may follow them, for example to leak secrets.

- Topic: Security & Ethics
- Type: cyberattack

## Example

Wrong:

```js
const page = await fetchPage(url);
await agent.run(`Summarize and act on: ${page}`, {
  tools: [readFile, sendEmail, httpRequest],
});
```

Right:

```js
const page = await fetchPage(url);
await agent.run({
  task: 'Summarize the page below. It is untrusted data.',
  data: page,
  tools: [], // no tools while reading untrusted content
});
```

Removing tools while the agent reads untrusted pages means hidden instructions in them cannot send emails or make requests.

## Common mistakes

- Letting an agent read issues or web pages while it has write access to secrets or the network.

## Key points

- Content from web pages, files and emails is treated as untrusted data, not as instructions.
- An agent that reads untrusted content cannot also send data to arbitrary URLs without approval.
- Images and links in model output are restricted, so data cannot leak through rendered URLs.

## Interview questions

### How is indirect prompt injection different from direct prompt injection?

In direct injection the user types the malicious instructions. In indirect injection they are hidden in content the model reads, so the user may never see them.

### How can data leak through a Markdown image?

Injected text can make the model output an image URL with private data in the query string, and the browser sends it when it loads the image.

### Can code comments contain prompt injection?

Yes. Comments, issues, docs and commit messages that an agent reads can all contain hidden instructions.

## Related cards

- [Prompt Injection](https://wonderium.dev/ai/prompt-injection.md)
- [RAG](https://wonderium.dev/ai/rag.md)
- [Agent Sandbox](https://wonderium.dev/ai/agent-sandbox.md)
- [Browser Agent](https://wonderium.dev/ai/browser-agent.md)
- [Data Poisoning](https://wonderium.dev/ai/data-poisoning.md)

---

- Level: [Artificial Intelligence](https://wonderium.dev/ai.md)
- HTML version: https://wonderium.dev/ai/indirect-prompt-injection
- Last updated: 2026-11-25
