AI Agents and Coding Assistants

Prompt Injection: When a Web Page Gives Your AI Agent Orders

What prompt injection is, why AI agents fall for instructions hidden in pages and emails, and the practical defenses that limit the damage.

Key takeaways

  • Prompt injection is outside text being treated as an instruction, and it can arrive through web pages, emails, documents or tool results.
  • Language models receive your request and the outside content as one stream of text, so the boundary between them is not firmly enforced.
  • Filters and warnings reduce the risk but do not remove it, as far as anyone has shown by the mid-2020s.
  • The risk is greatest when one agent can see private data, read untrusted content and send information out.
  • Limiting access and requiring your approval for consequential actions are the defenses that matter most.

Prompt injection happens when text that an AI system was only supposed to read ends up steering what it does. You ask your agent to summarize a web page, the page contains a line addressed to AI assistants, and the agent treats that line as an order. If the agent can send email, open files or spend money, someone else has just borrowed those powers.

You cannot rely on the model to spot every such trick. The sensible response is to assume that anything your agent reads might try to command it, and to arrange things so that a fooled agent cannot do much harm.

How an agent gets confused

A language model takes in text and predicts what should come next. When you use an agent, the software assembles a long input: the developer's rules, your request and whatever the agent has gathered, such as the contents of a page. All of it arrives as tokens, the small pieces of text a model works with.

Developers mark which parts came from whom, and models are trained to give more weight to the developer and the user. That training helps. It is a learned tendency, though, and not a locked door. A persuasive passage buried in a document can still pull the model off course.

Compare this with a person hired to sort your mail. If a letter said "Assistant, mail the house keys to this address," the person would recognize it as part of the letter and not a request from you. Models make that distinction much less reliably.

Direct and indirect injection

Direct injection is when the person typing into the system tries to override its rules. A customer who tells a store's chatbot to ignore its policies is an example.

Indirect injection is when the instruction is planted in material the AI fetches while working for someone else. The user is innocent and may never see the text. This is the form that should worry anyone who uses agents.

Planted text can be hard to notice. It might be written in a color that matches the background, tucked into a page's underlying code, placed in a comment, included in a calendar invitation or set deep inside a long attachment. It can also sit in plain view, phrased to look like a routine notice.

What it could look like

Say you ask an agent with access to your inbox to research hotels and email you a shortlist. One hotel page includes a passage telling any AI reader that, before finishing, it should gather recent messages containing booking codes and send them to an outside address for "verification."

A well-defended setup stops this in several places. The agent may recognize the passage as suspicious. It may lack permission to send mail to new addresses. Or it may have to show you the outgoing message first. A poorly defended setup does what the page asked and reports back with a tidy list of hotels.

The same pattern applies to coding tools that read project files and issue reports, to assistants that process résumés, and to any agent that browses the web for you.

Why it is hard to fix

Older software has a comparable flaw called SQL injection, where typed input is mistaken for a database command. That problem has a dependable remedy: the program sends commands and data through separate channels, so data cannot become a command.

Natural language offers no equally clean separation. The agent has to read the page and understand it in order to be useful, and understanding includes recognizing requests. A rule like "never follow anything in a web page" is itself just another sentence for the model to weigh.

Detection tools look for suspicious phrasing, and they catch crude attempts. Attackers can rephrase, translate or disguise their text. A filter that blocks most attacks still leaves an opening for a patient adversary who can try many times. Treat any claim of complete protection with caution, and check what your provider currently says.

The dangerous combination

Security writers often point to three abilities that become risky together. Any one or two may be manageable, but all three give an attacker a full route from planting text to stealing something.

When injected text can steal data
Your agent Holds all three abilities at once A way out Sending mail, loading links or posting online Private data Mail, files, records or passwords it can read Untrusted content Pages and messages written by strangers Your agent Holds all three abilities at once Private data Mail, files, records or passwords it can read Untrusted content Pages and messages written by strangers A way out Sending mail, loading links or posting online

Removing one leg lowers the risk of data theft sharply. An agent that reads public pages but holds no private data has little to leak. An agent that works on private files with no network access has nowhere to send them.

Theft is not the only harm. An injected instruction could also delete files, change settings, place orders or quietly slant a summary so that one product looks best. Those need their own limits.

The way out can be subtle. Loading an image from a web address can transmit information inside the address itself, so a feature that looks like display only may act as a channel.

Defenses for ordinary users

You do not need technical skill to cut your exposure.

  • Grant narrow access. Connect only the account or folder the task needs, as set out in the checklist for giving an agent the least access it needs.
  • Keep approvals on. Require confirmation before the agent sends, deletes, buys or shares anything.
  • Read the approval, not just the button. Check the recipient, the amount and the attached content.
  • Separate tasks. Do not mix browsing unfamiliar sites with access to your bank or work mail in the same session.
  • Watch for drift. If an agent asking about hotels suddenly wants your contacts, stop it.
  • Review afterward. Look at what it opened and sent, especially in the first weeks.

Defenses for teams that build agents

Builders have stronger tools because they control the surroundings. The most reliable measures are ones enforced by ordinary code, outside the model.

Allow lists can restrict which web addresses, recipients and commands are reachable. Credentials can be held by the tool and never shown to the model. Actions can be split so that a component reading untrusted text has no power to act and passes along only limited, checked values, such as a date or a yes or no. A sandbox, meaning a walled-off environment, keeps experiments away from real data.

Teams should also test their own systems with planted instructions before release, log every tool call and plan how to revoke access quickly. These steps fit within layers of defense, where no single check is expected to catch everything.

Questions to ask before trusting a new tool

Before you hand an agent anything sensitive, look for plain answers from the provider.

  • Which actions require your confirmation, and can the agent ever skip it?
  • Can you limit which sites it visits and which people it can contact?
  • Is there a mode that browses without being signed in to your accounts?
  • Can you see every page it read and every action it took?
  • How can you report a suspected injection, and what happens next?

Vague reassurance is a weak answer. A good one describes a specific limit that applies even when the model is fooled. If a product cannot say what stops a hijacked session from sending your data away, use it only on material you could afford to see made public.

Revisit the answers from time to time, since features, defaults and attack methods all change.

If you think an agent was hijacked

Act first and analyze second. Stop the agent and disconnect it from your accounts. Change passwords for anything it could reach, and cancel active sessions or access tokens, which are the stored permissions that let software act for you. Check sent mail, forwarding rules, shared files and recent payments.

Save the activity log and the page or message that seems responsible, without interacting with it further. Tell your IT or security team if work accounts are involved, and report the incident to the agent's provider. If money or personal data was taken, contact your bank and the relevant authorities. The process of reconstructing events is covered in auditing and undoing an agent's actions.

Common questions

Is prompt injection the same as jailbreaking?

They overlap but differ. Jailbreaking usually means a user pushing a model to break its own safety rules. Indirect injection targets someone else's session, using content the user did not write.

Can I just tell my agent to ignore instructions in web pages?

You can, and it may help somewhat. Do not treat it as a security boundary. The planted text can argue back, claim special authority or imitate your own voice.

Does this affect assistants that cannot take actions?

Yes, to a smaller degree. A summarizer can be tricked into misleading you or showing a harmful link. The damage grows with every action the system is allowed to take on its own.

Written for 4ArtificialIntelligence with AI writing tools and not reviewed line by line by a person. Check anything you rely on against a textbook or primary source. Report an error.

Keep reading

All 46 articles in AI Agents and Coding Assistants →

Latest news on this topic