esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

How Do You Secure an Agent That Reads Email?

How to secure an AI agent that reads email: assume the mail is hostile, cut the ways data can leave, and keep a person on every send, for your AI interview.

In short

Assume the inbox is hostile, because any stranger can write to it. Then cut the ways data can leave: read-only access, drafts instead of sends, outside links and images removed in code, and a person who approves each message before it goes.

13 min readAdvancedCommon · estimateFacts checked 26 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

An agent that reads email can be fooled by any stranger who writes to the inbox, so I assume the mail is hostile. I cut the ways data can leave. The agent gets a read-only login and saves replies as drafts it cannot send. My code strips outside links and images, since those can carry data out. A person reads the exact text and recipient, then clicks send.

What does an email agent do, in plain words?

An email agent is an AI helper that reads an inbox, sums it up, and drafts or sends replies for a person. It works with that person's access, which is the point and also the risk. Much of the mail it reads is written by strangers.

Picture a shared-inbox clerk at a freight company who opens every supplier email. One message asks the clerk to copy the bank list to an outside address. A good clerk knows that is not an instruction from the boss. An AI model reads the email and the company's rules as one stream of text, so it may not tell them apart.

The same thing happens in software. Anthropic gives a worked example of an agent that reads email and drafts replies, where one vendor email contains hidden instructions embedded in white text. Those instructions tell the agent to forward confidential emails to an outside address.

Key words

Untrusted content
Outside text nobody on your side wrote or checked, such as mail from strangers.
Read-only login
Access that can look at mail but cannot delete, move or send it.
Draft
A reply saved for a person to check. The agent cannot send it.
Data leak
Private data leaving a system without permission, often hidden in a link or image.
Prompt injection
Text an AI model reads that overrides the developer's instructions, such as a hidden line in an email.

Why is an inbox a hard input to protect?

Simon Willison's "lethal trifecta" has three parts: access to private data, exposure to untrusted content, and a way to communicate outside. An inbox gives you all three at once.

  • “Something as simple as a tool that can access your email? That's a perfect source of untrusted content: an attacker can literally email your LLM and tell it what to do!”

    Simon Willison

  • “If your agent combines these three features, an attacker can easily trick it into accessing your private data and sending it to that attacker.”

    Simon Willison

  • Private data

    Keep it

    Reading mail is the job, so this part stays.

  • Untrusted content

    Accept it

    Strangers can always write to an inbox.

  • The way out

    Cut it first

    Sending, links and images are what move data.

So the design question is what a tricked agent can reach. An email agent keeps the first two parts, so the work goes into the third.

How do you cut the way out, step by step?

Start with the fewest powers, then add checks that live in code. The model can ask for an action, but code decides whether it runs. OWASP's guidance says authorisation should be enforced in logic, with no LLM deciding.

There are three common routes data can leave by. The first is a send tool, the obvious one. The second is a link a reader clicks. The third is quieter: a markdown image. The model writes an image tag whose web address carries the data, and the reader's browser fetches it on its own. Microsoft's security team describes this as a model made to output an HTML image tag, or the markdown equivalent, whose source address is the attacker's server. OWASP's 2026 list describes the same risk: the model inserts a markdown image whose URL carries the private conversation to a domain the attacker controls, and the user sees only the rendered picture.

Microsoft's answer was to deterministically block the impact. Its blog says it took steps to deterministically block the security impact, here the data leak.

Read, draft, approve: a mail agent that stays safe

Stranger's email

may hide an order in white text

Mail agent

reads with a read-only login

Your code checks

Remove outside links

links and images can carry data out

Save as draft

the model cannot send a draft

Person approves

sees the exact recipient and text

Sent

only after a person's click

  1. 1The stranger's email reaches the agent as text it reads, and the model may follow it.
  2. 2The agent's reply goes to code before anyone sees it.
  3. 3Code strips outside links and images, then keeps the reply as a draft.
  4. 4A person sees the exact recipient and full text.
  5. 5Only that person's click sends the mail.
A stranger's email reaches the agent as text it may follow. Code strips outside links and saves a draft. A person sees the exact text and recipient before anything is sent.
  1. 1

    Give read-only access

    The mail tool can read and nothing else. OWASP's excessive agency guidance says a mail tool may only need to read, so it should not be able to delete or send.

  2. 2

    Save replies as drafts

    The agent writes a draft and cannot send it. Microsoft describes Copilot in Outlook this way: it writes the text, and the user must approve it and send the email.

  3. 3

    Strip outside links and images

    Code removes web links and images before a reply is shown. A rendered picture can leak data with no click, so this step runs every time.

  4. 4

    Show the exact action

    The approver sees the real recipient, attachments and full text, not a summary. OWASP warns that invisible-character smuggling can make the displayed action differ from the executed one, so the approver must see what will actually run.

  5. 5

    Cap, log and alert

    Limit sends per day, log every tool call, and alert on a new recipient. OWASP suggests halting or escalating when thresholds are crossed.

A system prompt with clear allow and deny rules is useful, but OWASP calls that a partial control, because an attacker who infers the prompt can bypass it. Willison is just as blunt: "we still don't know how to 100% reliably prevent this from happening." So the limits must hold when the model is fooled.

What if the agent really has to send mail?

Sometimes a send is the job, such as confirming a delivery date with a supplier. Then count the legs. The rule of two, which OWASP cites from Meta AI, says that untrusted input, sensitive data and outside action together are high risk. An agent with all three needs approval for every action. An agent with two needs a written residual-risk assessment, which is a note of what can still go wrong, plus checks in code.

Rule of two: count the risky legs

The agent's three legs

Reads outside mail

anyone can write to the inbox

Private data

supplier bank details, contracts

Sends or changes

can send mail or edit records

Two legs

Write down the risk

plus code checks and logs

All three legs

Approve every action

a person signs off each step

Live and watched

risks written down and owned

  1. 1Two legs take this path.
  2. 2All three legs goes down this path, with a person on every risky step.
  3. 3The two-leg agent goes live with a written risk note and code checks.
  4. 4The three-leg agent goes live only with approval on each action.
OWASP's rule of two counts three legs: outside input, private data, and power to act. Three legs need approval on every action. Two need a written risk note and checks in code.

For the inbox agent, drop the send leg where you can. Reading mail with private data leaves two legs, so you write down the risk, keep drafts, and let a person send.

What does a guarded mail agent do with one bad email?

Take a shared accounts-payable inbox with about 1,200 supplier emails a month. Say one in a thousand is hostile. That is one or two bad messages a month, and each could hide an order. The numbers are made up, but the risk is real. Here is a small version of the gate that sits between the model and the mail server.

Python
# A mail agent's gate. Once it has read outside mail, the session is marked, and a marked session can send only after a person approves the exact text.
import re

KNOWN = {"supplier-team@example.com", "priya@example.com"}
LINK = re.compile(r"https?://\S+")

def clean(reply):
    # Links and images can carry data out when they render, so every web link is removed before a person sees them. shortcut: only http and https links are caught, widen before real use.
    return LINK.sub("[link removed]", reply)

def act(tool, to="", reply="", marked=False, human_ok=False):
    if tool == "draft_reply":
        return "DRAFT: " + clean(reply)
    if tool == "send_reply":
        reply = clean(reply)
        if to not in KNOWN:
            return "BLOCKED: " + to + " is not a known contact"
        if marked and not human_ok:
            return "HELD: a person must approve the exact text to " + to
        return "SENT to " + to
    return "BLOCKED: no such tool: " + tool

reply = "Invoice 4471 is paid. See https://attacker.example.net/pay?data=bank-list"
print(act("draft_reply", reply=reply, marked=True))
print(act("send_reply", to="attacker@example.net", reply=reply, marked=True))
print(act("send_reply", to="priya@example.com", reply=reply, marked=True))
print(act("send_reply", to="priya@example.com", reply=reply, marked=True, human_ok=True))
print(act("delete_mail"))

Output

DRAFT: Invoice 4471 is paid. See [link removed]
BLOCKED: attacker@example.net is not a known contact
HELD: a person must approve the exact text to priya@example.com
SENT to priya@example.com
BLOCKED: no such tool: delete_mail

Read the output line by line. The bad message can reach the draft, but the link in it is removed. A send to an unknown address is blocked. A send to a known contact from a marked session waits for a person, and only that person's approval lets it go.

What does the interviewer want to hear?

A strong answer covers

  • The inbox is untrusted: any stranger can write to it.
  • Name the three parts: private data, outside text, and a way out.
  • Cut the way out first: read-only access, drafts, no outside links or images.
  • Code decides, the model only asks, and approval shows the exact action.
  • Rule of two: with all three parts, approval on every action.
  • No complete fix today, said plainly, so the limits must hold when the model is fooled.

Common traps

  • Trap"Our system prompt tells the agent to ignore instructions in emails."

    BetterA prompt line is a partial control. Put the limit in code the model cannot change.

  • Trap"The agent only reads, so it is safe."

    BetterReading is only the first part. Output can still leak through links and images, so check what it writes.

  • Trap"A guardrail product catches the attacks."

    BetterDetectors lower the odds. Willison says that in web application security, a 95% catch rate is a failing grade.

Can you spot the risky setup?

Spot the risky setup

Which mail agent setup is the risky one?

Quick check

Your agent reads supplier mail and can send replies. Which change cuts the biggest risk first?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q201What is prompt injection?12 min
  2. Q202Direct vs indirect prompt injection?10 min
  3. Q209How do you build defence in depth against injection?13 min
  4. Q225What is the dual-LLM (quarantine) pattern?Coming soon
  5. Q226What is spotlighting untrusted content?Coming soon
  6. Q179Excessive agency and least privilege?11 min

Learn it in depth

Last updated on 26 November 2026

Putting an agent on a shared inbox?

I design and build AI agents with these guardrails in place, plus the screens people use them through. Book a short call and tell me what your agent needs to do.