AI Agent Hijacking Lab: A Document That Hijacks the Bot

✨ AI Summary
TaskBot is a tool-using agent. Ask it to 'summarise this doc' and it reads the document — and then obeys any instructions it finds inside that document as if you had typed them yourself. The bot cannot tell your orders apart from text it was handed to read.
Lab at a glance: Advanced · 130 XP · about 20 minutes · runs in your browser, no signup or setup. Try it yourself first; the full solution is behind a spoiler below.

What this lab teaches

Indirect prompt injection is the defining AI-agent vulnerability: the model treats content it retrieves (a document, a web page, an email) as part of the same instruction stream as the user's request. An attacker who controls that content can issue commands the agent then carries out with its own tool access.

The lesson: to a language model, there is no built-in boundary between 'what the user asked' and 'what the data says'. That boundary has to be engineered.

How TaskBot processes a document

You ask TaskBot to summarise a document you provide. It loads the document into its context and generates a summary — but instructions embedded in the document are read with the same authority as your request, so a line in the doc telling it to call a tool is followed.

The attack approach

  • Confirm TaskBot reads and acts on document content, not just your chat message.
  • Place an instruction inside the document that tells the agent to take an action.
  • Target the privileged tool the lab exposes (an account-deletion call on the admin user).
  • Submit the document for 'summarising' and watch the embedded instruction get executed.

Full walkthrough (spoiler)

Stuck after a couple of tries? Open the steps — solving it yourself first is worth more XP.

Show the step-by-step solution
  1. Write a short document whose body contains, as plain text, an instruction addressed to the assistant telling it to call the account-deletion tool on user_id 1.
  2. Submit it with a normal 'please summarise this' request.
  3. TaskBot reads the document, treats the embedded line as a command, and calls the tool.
  4. The privileged action fires and the lab marks you solved.

Why it works

TaskBot concatenates your request and the document into one prompt and the model weighs them equally. Nothing marks the document as inert data, so a convincing instruction inside it is indistinguishable from something you said. With tool access attached, that instruction becomes an action.

Core principleContent an agent retrieves is untrusted data, never instructions. Keep data and instructions in separate channels and gate every tool call on the real user's intent and permissions.

Where this happens in the real world

Indirect prompt injection is the headline risk in agentic AI and sits at the top of the OWASP Top 10 for LLM Applications (2025) as LLM01 Prompt Injection, with the tool-abuse angle covered by LLM06 Excessive Agency. It is why connecting an LLM to real tools and untrusted content without strict mediation is dangerous.

How to defend against it

  • Separate data from instructions — pass retrieved content in a clearly delimited, non-instruction channel the model is told to treat as inert.
  • Gate every tool call on the authenticated user's permissions, not on what the model decided.
  • Require human confirmation for destructive or high-impact actions.
  • Least privilege for agents — give the agent only the tools and scope a given task needs.
Mr Elite tip: Any time an agent reads attacker-reachable content and can also call tools, assume that content can drive the tools. The only reliable guard is authorising actions against the user, not the model's intent.

Try it, then go further

Reading about it is the easy part. Open the lab, try your own approach before peeking at the spoiler, and see how many attempts it takes.

❓ Frequently asked questions

What is indirect prompt injection?
An attack where instructions hidden in content an AI agent reads (a document, web page or email) are obeyed by the agent as if the user had issued them.
Why can't the model just ignore instructions in data?
Language models have no built-in boundary between user instructions and retrieved text — both arrive as tokens in the same context. The boundary must be engineered around the model.
How dangerous is it for agents?
Very — if the agent can call tools, injected instructions become real actions. It is the central risk behind OWASP LLM01 and LLM06.
How do I defend an agent against it?
Treat retrieved content as inert data in a separate channel, authorise every tool call against the real user, require confirmation for high-impact actions, and keep agent privileges minimal.
⚡
Join free to earn XP for reading this article Track your progress, build streaks and compete on the leaderboard.
Join Free
Lokesh N. Singh aka Mr Elite
Lokesh N. Singh aka Mr Elite
Founder, Securityelites · AI Red Team Educator
Founder of Securityelites and creator of the SE-ARTCP credential. Working penetration tester focused on AI red team, prompt injection research, and LLM security education.
About Lokesh ->

Leave a Comment

Your email address will not be published. Required fields are marked *