AI Tool-Output Injection Lab: Hostile Search Results Drive the Agent

✨ AI Summary
ResearchBot searches the web, then feeds the results straight back into its own context to reason over them. Its guardrails check what you say — but not what the search results say. Poison a result and the agent follows it.
Lab at a glance: Advanced · 145 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

Tool-output injection is indirect prompt injection through the agent's own tools. The results a tool returns (search hits, API responses, file contents) are injected into the model's context, and if the agent treats them as trusted reasoning material, attacker-controlled output becomes attacker-controlled instructions.

The lesson: a tool result is just more untrusted input. An agent that guards its user input but trusts its tool output has left the back door open.

How ResearchBot uses its tools

You ask ResearchBot to research a topic. It calls its search tool and pours the returned text into its context, then decides what to do next — including whether to call its internal-message tool. Content in the search results is read with the same trust as the agent's own plan.

The attack approach

  • Confirm ResearchBot feeds tool results back into its own reasoning context.
  • Arrange for a search result to contain an instruction aimed at the agent.
  • Direct that instruction at the internal-message tool with the recipient and body the lab wants.
  • Trigger a research query that surfaces the poisoned result.

Full walkthrough (spoiler)

If the agent summarises the result instead of acting on it, make the instruction clearer — open the steps.

Show the step-by-step solution
  1. Get a hostile line into the search results the agent will read — an instruction telling it to send an internal message.
  2. Phrase it so the agent treats it as a next step: call send_internal_message to the security-team recipient with the audit body the lab specifies.
  3. Run the research query so the agent fetches and ingests that result.
  4. The agent follows the embedded instruction and sends the message. The lab marks you solved.

Why it works

ResearchBot's guardrails inspect your message, then stop. The search results re-enter the context unchecked, and the model cannot tell a genuine finding from a planted command. Because the agent can act on what it 'reads', hostile tool output becomes a hostile instruction.

Core principleTool output is untrusted input. Sanitise and delimit it, and never let retrieved text alter the agent's plan or trigger tools on its own.

Where this happens in the real world

Trusting retrieved content as part of the instruction stream is the canonical RAG and agent vulnerability — OWASP LLM01 Prompt Injection, with the tool-abuse consequence under LLM06 Excessive Agency. As agents chain more tools, each tool result is another injection surface.

How to defend against it

  • Treat every tool result as untrusted data, wrapped and clearly marked as non-instruction.
  • Re-check guardrails after tool calls, not only on the initial user message.
  • Gate sensitive tools (messaging, deletion, transfers) on the user's intent and permissions.
  • Constrain the agent's plan so retrieved text cannot introduce new high-impact steps.
Mr Elite tip: For any agent that reads then acts, map every point where external content re-enters the context. Each one is an injection surface, and guardrails that only run on user input miss all of them.

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 tool-output injection?
Indirect prompt injection carried through an agent's own tool results — search hits or API responses that contain instructions the agent then follows.
Why do guardrails miss it?
Many guardrails only score the user's message. Tool results re-enter the context afterwards, unchecked, so planted instructions slip past.
How is it different from direct prompt injection?
Direct injection comes from the user's message; tool-output injection comes from content the agent fetched. Both are read as instructions if not isolated.
How do I defend against it?
Treat tool output as untrusted data, re-run guardrails after tool calls, gate sensitive tools on real user intent, and stop retrieved text from adding steps to the plan.
⚡
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 *