[Blog](https://mailforbots.com/blog)

# Email 2FA in browser agents: Playwright MCP and Browser Use

Published October 12, 2026 · Updated October 12, 2026

A browser agent stalls at "enter the code we emailed you" because it has no inbox to read. The fix is to give it one it controls, plus a tool that blocks until the email arrives and returns the code as a field. With Mail for Bots that is `create_inbox`, then `wait_for_message`, then reading `extracted.codes`.

The same pattern works with any browser driver, including Playwright MCP, because the inbox is just another set of tools the agent can call. Over MCP the agent finds these tools with `search_tools` and runs them via `call_tool`. The browser types; the mail server waits.

## Why does a browser agent get stuck on email codes?

Clicking and typing are easy for an agent. Receiving is not: the code goes to an address the agent cannot open. Common workarounds are worse than the problem. A human forwards the code from a personal inbox, or the agent polls a shared mailbox and parses raw HTML. Both are slow, and the second one lets stray mail steer the run.

A dedicated inbox removes the human from the loop and keeps the code out of your personal mail.

## What is the flow for a sign-up with an emailed code?

1. The agent calls `create_inbox` (optionally with `ttl_minutes` so it deletes itself) and gets back an address.
2. It types that address into the site's sign-up form in the browser.
3. It calls `wait_for_message`, filtering with `from_contains` or `subject_contains` so only the right sender counts. The call returns as soon as the email arrives, or returns null on timeout. It returns the first unread matching message and marks it read; use `get_message` to read it again.
4. It reads `extracted.codes` (or a verify link from `extracted.links`) from the returned message.
5. It types the code back into the browser and continues.

If you drive the same flow from your own script instead of MCP, the REST equivalents are `POST /inboxes` and `GET /inboxes/:inbox/wait`:

REST

```
# 1. create a throwaway inbox (returns the new inbox, including its address)
curl -X POST "$BASE/api/v1/inboxes" \
  -H "Authorization: Bearer $BOTMAIL_KEY" -H "Content-Type: application/json" \
  -d '{ "ttl_minutes": 30 }'

# 2. type the returned address into the site, then block for the email
curl "$BASE/api/v1/inboxes/INBOX_ID/wait?from_contains=example.com&timeout_seconds=90" \
  -H "Authorization: Bearer $BOTMAIL_KEY"
# 200: the full message, including extracted.codes and extracted.links
# 408: nothing arrived in time, retry
```

## How do I pair it with Playwright MCP?

Put both servers in one MCP client config. Playwright MCP owns the page: navigate, fill, click. Mail for Bots owns the mailbox: create, wait, read. The model decides when to switch between them, and neither server needs to know about the other.

MCP client config (shape varies by client)

```
{
  "mcpServers": {
    "playwright": { "command": "npx", "args": ["@playwright/mcp@latest"] },
    "mailforbots": {
      "url": "<MCP URL from the setup page>",
      "headers": { "Authorization": "Bearer YOUR_API_KEY" }
    }
  }
}
```

Exact config syntax differs by client; the [MCP email server](https://mailforbots.com/mcp-email-server) page lists it for each one. Browser Use can also load MCP servers or call REST; check its docs for the config syntax.

| Step | Server | Tool |
| --- | --- | --- |
| Make an address | Mail for Bots | create_inbox |
| Fill the sign-up form | Browser (e.g. Playwright MCP) | browser_navigate, browser_type, browser_click |
| Wait for the email | Mail for Bots | wait_for_message |
| Enter the code | Browser (e.g. Playwright MCP) | browser_type, browser_click |
| Clean up | Mail for Bots | delete_inbox |

## What does the agent get back?

`wait_for_message` and `get_message` return the full message (with an attachments list and an `extracted` object). `wait_for_message` only matches unread inbound messages and marks the one it returns as read. `extracted.codes` holds one-time codes (4 to 8 digits, split codes like 482-913, and 6 to 8 character uppercase alphanumeric codes containing a digit). `extracted.links` holds action links labelled by kind: verify, reset, login, unsubscribe or other.

So the model reads a field instead of guessing which number in the body is the code. Plus-addressing lets one inbox serve many sites: filter `to_contains` on the tag, such as `+github`. See [plus-addressing](https://mailforbots.com/docs/plus-addressing).

## What are the limits?

- CAPTCHAs are not solved. Mail for Bots handles the email step only; a CAPTCHA before or after it still needs a human or another approach.
- Some sites reject disposable or shared domains. On Pro you can create inboxes on your own [custom domain](https://mailforbots.com/docs/domains), which many sites accept, though none is guaranteed.
- Code extraction is pattern-based. If a site sends a code in an unusual format, fall back to reading the message body.
- `wait_for_message` waits up to 300 seconds (default 60). Slow senders need a retry.
- Respect each site's terms. This is for real workflows, not mass account creation.

Plans: Free includes 3 inboxes; Pro is $20 a month with 100 inboxes and up to 10 custom domains. See [pricing](https://mailforbots.com/pricing). If you prefer event-driven delivery, Mail for Bots also supports [webhooks](https://mailforbots.com/docs/webhooks). For other options see [best email for AI agents](https://mailforbots.com/blog/best-email-for-ai-agents-2026).

## How do I keep a browser agent safe with inbound email?

Treat every inbound email as untrusted text. A message can contain instructions aimed at your model, and a browser agent can act on them. Prefer `extracted.codes` over free-text interpretation, and only accept mail from the expected sender by filtering on `from_contains`.

Never give the signing-up agent `mail:send`, and have any agent that writes mail use drafts, which wait for a human to send. There are two key setups:

- The agent creates its own inbox. Use a key scoped to `mail:read`, `inboxes:manage` and `drafts:write`, with no `mail:send` and no `inbox_ids` restriction.
- You pre-create the inbox. Give the agent a key restricted with `inbox_ids`. Inbox-restricted keys cannot create inboxes, so the agent only waits and reads.

Details are in [AI agents and email verification codes](https://mailforbots.com/blog/ai-agents-email-otp-verification-codes) and [human approval for agent email](https://mailforbots.com/blog/human-approval-for-ai-agent-email).

## Checklist for agent builders

- Both servers (browser and mail) are in the same client config.
- One inbox per run, with `ttl_minutes` set.
- `wait_for_message` filters on sender or subject, with a timeout you chose.
- The agent uses `extracted.codes` or a verify link, not the whole body.
- The key has no `mail:send` scope. If the agent creates inboxes it needs `inboxes:manage`; otherwise pre-create the inbox and restrict the key with `inbox_ids`.
- A timeout path exists: retry once, then report to a human.
- A CAPTCHA path exists: stop and ask, do not loop.
- On sites that block shared domains, switch to a Pro custom domain.

Ready to try it? [Start free](https://mailforbots.com/#/signup), connect via the [quickstart](https://mailforbots.com/docs/quickstart), and have your browser agent sign up somewhere in minutes. For the broader picture see [email for AI agents](https://mailforbots.com/email-for-ai-agents).

## Frequently asked questions

**How does an AI agent get an emailed 2FA code in a browser?**

It creates an inbox with create_inbox, types the address into the site, calls wait_for_message to block until the email arrives, reads extracted.codes from the returned message, and types the code back into the browser. Over MCP these tools are found with search_tools and run via call_tool.

**Does this solve CAPTCHAs or sites that block disposable email?**

No. CAPTCHAs are not solved. If a site rejects shared-domain addresses, Pro lets you create inboxes on your own custom domain, which many sites accept, though none is guaranteed.

**Is it safe to let a browser agent read inbound email?**

Treat inbound email as untrusted text. Prefer extracted codes over free text, filter by sender with from_contains, use a key without mail:send scope, and have outbound replies saved as drafts for human approval.

[Start free](https://mailforbots.com/#/signup) [Read the quickstart](https://mailforbots.com/docs/quickstart)

## Related reading

- [What is an agent inbox? Definition and how it differs from a sender API](https://mailforbots.com/blog/what-is-an-agent-inbox)
- [How to give an n8n AI agent its own email inbox](https://mailforbots.com/blog/n8n-ai-agent-email-inbox)
- [How to give a LangChain or LangGraph agent an email inbox](https://mailforbots.com/blog/langchain-agent-email-tool)
