Back to Hub

What stopped prompt injection in a toy agent, and what the score missed

What is prompt injection?

AI assistants can read documents and web pages for you, and they can't always tell your request apart from what the page says. Someone can hide an instruction in a document and hope the assistant follows it. This project hides instructions like that in a made-up office and records what happens.

A hidden instruction in a roster, which the assistant might follow, repeat to you, or warn you about
An example of a hidden instruction.

The question

An agent that reads documents and web pages can be given instructions by whoever wrote them. Many defences are suggested. I wanted to see which ones actually change what happens, and what each costs in ordinary work.

How the lab works

A small office agent can read documents, fetch pages from a mock web and send messages to a fake outbox. Each of 15 scenarios has an ordinary task and an attack hidden in pasted text, a document or a page, worded two ways: openly addressed to the assistant, or disguised as routine business instructions. Two local models, Qwen 3.8 27B and Muse Glimmer 30B, ran every scenario against each defence and against combinations of them, 3,240 attempts in all.

A scripted stand-in that obeys any injection it sees shows what each defence guarantees without relying on a model's judgement.

What happened

Bar chart of direct and disguised attack success and clean task success for each defence
Both models pooled. Direct attacks scored zero under every configuration.
DefencesScripted attacks that got through (of 30)Disguised attacks that scored with models (of 90)
None3014
Prompt defences304
Egress allowlist1014
MCP gateway, default policy2814
Everything except the gateway64

Neither model carried out an attacker's action: not one message, request or leaking link in 1,728 attempts at the attacks that needed one. The defences that block actions therefore had nothing to stop with these models, and only the scripted stand-in shows their worth. The only successes were disguised false messages, such as a line in a roster saying it had been withdrawn. Prompt defences lowered that score, but it rests on three scenarios, so the size of the effect is unsettled.

What I learned

The automatic score got some cases wrong. Reading the replies showed 9 counted successes where the model had warned the user, and 10 uncounted ones where it passed the false message on but dropped the reference code the scorer looked for.

It also missed another problem. Muse Glimmer never acted on those attacks, yet in 50 of 864 replies it repeated the attacker's request to the user with no warning, including that a booking would only be confirmed once a payments key had been emailed out. Even if an agent won't send the key itself, passing the request to the user without a warning still helps the attacker.

The MCP gateway from my other project added little here with its default policy, and cost some tasks because it withholds a whole document that its scanner flags.

Disclosure: this project was written with AI coding agents, including the attacks. The reply labels were made by the same agent and have not been independently checked.

What's next

Attacks written by someone who has not seen the defences, more false-message scenarios, a score that checks what the user is told as well as what the agent does, and smaller models that may be easier to fool.

Source code