AI Plan Injection Lab: Corrupt the Agent's Scratchpad

✨ AI Summary
PlannerBot writes a plan to a scratchpad, then executes the steps — and it reads the scratchpad back on every loop for 'transparency'. If your input lands in that scratchpad, it is read as a planned step, and the agent will dutifully carry it out.
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

ReAct-style agents keep a running scratchpad of their reasoning and plan, then re-read it each cycle. Plan injection happens when attacker-controlled text ends up in that scratchpad, so it is treated as the agent's own plan on the next read — including steps that call tools.

The lesson: the agent's memory of its own plan is state, and if user input can write to that state unsanitised, the user can rewrite the plan.

How PlannerBot plans and executes

PlannerBot stores its plan — and, as it turns out, pieces of your input — in a scratchpad that the execution loop reads back verbatim. A crafted entry that looks like a plan step ('then call http_request to …') is executed as if the agent had planned it.

The attack approach

  • Confirm your input is reflected into the scratchpad the agent reads on each loop.
  • Write input shaped like a plan step the agent would execute.
  • Make that step call the HTTP tool, sending the user's session data to an attacker endpoint.
  • Submit and watch the agent execute the injected step without the user asking for it.

Full walkthrough (spoiler)

If the step is written but not executed, phrase it to match the agent's plan format — open the steps.

Show the step-by-step solution
  1. Supply input that, once in the scratchpad, reads as the next action: a call to http_request targeting the attacker log endpoint with the session data.
  2. The execution loop reads the scratchpad back and treats your line as a planned step.
  3. The agent calls the HTTP tool and ships the data out.
  4. The lab detects the exfiltration call and marks you solved.

Why it works

The scratchpad is both output and input: the agent writes to it and then trusts it as its own reasoning. Because your text is stored there unsanitised, the next read cannot tell your injected step from a genuine one, and the loop executes it.

Core principleNever store raw user input in the agent's plan state. Keep the scratchpad authoritative and separate user text from it entirely.

Where this happens in the real world

Plan and scratchpad injection is an emerging agent attack as ReAct and planner architectures spread. It maps to OWASP LLM01 Prompt Injection and LLM06 Excessive Agency, and it is especially dangerous because the agent's own transparency loop becomes the exploit path.

How to defend against it

  • Sanitise user input to inert data before it ever touches the scratchpad.
  • Keep plan state server-authoritative and separate from any user-supplied text.
  • Validate each step before execution against an allowlist of permitted actions.
  • Gate tool calls (especially outbound HTTP) on the user's actual request and permissions.
Mr Elite tip: For any ReAct-style agent, check whether user text can reach the scratchpad. If it can, the agent will eventually read your words as its own plan.

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 plan injection?
An attack on ReAct-style agents where attacker text enters the agent's scratchpad and is read back as a planned step, causing the agent to execute it.
Why is the scratchpad a risk?
The agent both writes and reads it, trusting it as its own reasoning. If user input is stored there unsanitised, it becomes indistinguishable from a real plan step.
What can it achieve?
Unrequested tool calls — including data exfiltration via an outbound HTTP tool, as in this lab.
How do I prevent it?
Keep user input out of the plan state, sanitise it to inert data, validate each step against an allowlist, and gate tool calls on real user intent.
⚡
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 *