# 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.

AI and LLM interview question Q227, Guardrails and AI safety. Advanced, common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/how-do-you-secure-an-agent-that-reads-email

## Say it in 30 seconds

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.

## Say it in 2 minutes

An email agent reads whatever arrives, and anyone on the internet can send it mail. So a stranger's message can carry instructions, and the agent may follow them. The worst case needs three things together: access to private data, exposure to outside text, and a way to send information out. Simon Willison calls that combination the lethal trifecta. An inbox has all three by default, so I start from there.

The first cut is power. The agent gets a read-only login, so it can't delete, move or send, and it gets only the tools its job needs. Replies are saved as drafts. Before anyone sees a reply, my code removes links and images that point outside, because a picture can quietly pass data to a server. Then a person reads the exact recipient and the full text, and clicks send.

Some agents must send, so I count their risky parts: reading outside input, touching private data, and acting outside. OWASP's guidance, citing Meta AI's rule of two, says all three together need approval for every action. For two parts, OWASP says a written residual-risk assessment is needed, and I would add checks in code. I also cap sends per day, log every tool call, and test with people who try to break it.

I'd be honest about limits. Nobody has a complete fix for prompt injection today, so I never claim one. My answer is limits in code that still hold when the model is fooled.

## 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.

- **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.

*Diagram, Read, draft, approve: a mail agent that stays safe: 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. The stranger's email reaches the agent as text it reads, and the model may follow it.
2. The agent's reply goes to code before anyone sees it.
3. Code strips outside links and images, then keeps the reply as a draft.
4. A person sees the exact recipient and full text.
5. Only that person's click sends the mail.

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. **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. **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. **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. **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.

*Diagram, Rule of two: count the risky legs: 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.*
1. Two legs take this path.
2. All three legs goes down this path, with a person on every risky step.
3. The two-leg agent goes live with a written risk note and code checks.
4. The three-leg agent goes live only with approval on each action.

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:

```text
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." Better: A prompt line is a partial control. Put the limit in code the model cannot change.
- Trap: "The agent only reads, so it is safe." Better: Reading 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." Better: Detectors 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?

A. Tools: read_inbox and create_draft. Sending needs a person's click in the approval screen.
B. Tools: read_inbox and send_email. The model picks the recipient from the message text.
C. Mailbox login: read only. Outside links are removed before a reply is shown.
D. Tools: read_inbox and create_draft. Known contacts come from a list in code.

**Answer:** B. The model picks the recipient, so one hidden line in an email can choose where your data goes. Recipients should come from a list in code, and sends should wait for a person.

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

A. Add a line to the system prompt telling it to ignore instructions in email
B. Remove the send tool, so replies are drafts that a person sends
C. Move to a larger model that follows instructions more closely
D. Log every email the agent reads for later review

**Answer:** B. Removing the way out stops data leaving the mailbox, whatever the model reads. A prompt line is only a partial control, a bigger model does not change what the agent can reach, and logs show a leak only after it happens.

## Can you answer these from memory?

**Flash cards**

- **Which part of the trifecta do you cut first?** The way out: send, outside links and images. Reading mail is the job.
- **What is a markdown image leak?** The model writes an image whose web address carries data. The browser fetches it with no click.
- **What does a read-only login stop?** Deleting, moving or sending mail. It limits the damage a tricked agent can do.
- **Where should recipients come from?** A known list in code, never from the model's own choice of address.
- **What does the rule of two say?** All three together need approval on every action. Two need a written risk note and code checks.
- **What must the approver see?** The exact recipient, attachments and full text, not a summary.

## Likely follow-up questions

- Q201 What is prompt injection? https://designervenkat.online/interview/ai/what-is-prompt-injection
- Q202 Direct vs indirect prompt injection? https://designervenkat.online/interview/ai/direct-vs-indirect-prompt-injection
- Q209 How do you build defence in depth against injection? https://designervenkat.online/interview/ai/defence-in-depth-against-prompt-injection
- Q225 What is the dual-LLM (quarantine) pattern? (full answer coming)
- Q226 What is spotlighting untrusted content? (full answer coming)
- Q179 Excessive agency and least privilege? https://designervenkat.online/interview/ai/excessive-agency-and-least-privilege

## Learn it in depth

- [Prompt injection defences](https://designervenkat.online/learn/ai-guardrails/injection-countermeasures)
- [Agentic AI security](https://designervenkat.online/learn/ai-guardrails/agentic-ai-security)
