Email Sandbox for AI Agents
Test every email your AI agent generates
Route every email your AI workflow generates to a safe sandbox where you can inspect and validate before it reaches a real inbox. Catch bad replies, hallucinations, and formatting issues before they go live. Flip to live sending with one config change.
-
cURL
cURL.txt
Copy
// Claude or Cursor
{
"mcpServers": {
"mailtrap": {
"command": "npx",
"args": ["-y", "mcp-mailtrap"],
"env": {
"MAILTRAP_API_TOKEN": "your_mailtrap_api_token",
"DEFAULT_FROM_EMAIL": "your_sender@example.com",
"MAILTRAP_ACCOUNT_ID": "your_account_id",
"MAILTRAP_TEST_INBOX_ID": "your_test_inbox_id"
}
}
}
}
// VS Code
{
"mcp": {
"servers": {
"mailtrap": {
"command": "npx",
"args": ["-y", "mcp-mailtrap"],
"env": {
"MAILTRAP_API_TOKEN": "your_mailtrap_api_token",
"DEFAULT_FROM_EMAIL": "your_sender@example.com",
"MAILTRAP_ACCOUNT_ID": "your_account_id",
"MAILTRAP_TEST_INBOX_ID": "your_test_inbox_id"
}
}
}
}
}
// Claude Code (asdf)
{
"mcpServers": {
"mailtrap": {
"command": "/Users/<username>/.asdf/shims/npx",
"args": ["-y", "mcp-mailtrap"],
"env": {
"PATH": "/Users/<username>/.asdf/shims:/usr/bin:/bin",
"ASDF_DIR": "/opt/homebrew/opt/asdf/libexec",
"ASDF_DATA_DIR": "/Users/<username>/.asdf",
"ASDF_NODEJS_VERSION": "20.6.1",
"MAILTRAP_API_TOKEN": "your_mailtrap_api_token",
"DEFAULT_FROM_EMAIL": "your_sender@example.com",
"MAILTRAP_ACCOUNT_ID": "your_account_id",
"MAILTRAP_TEST_INBOX_ID": "your_test_inbox_id"
}
}
}
}
// MCP Bundle (MCPB)
# Build TypeScript and pack the MCPB bundle
npm run mcpb:pack
# Inspect bundle metadata
npm run mcpb:info
# Sign the bundle for distribution (optional)
npm run mcpb:sign
Trusted by teams building with AI
Every endpoint your agent needs for email workflows
Create sandboxes, capture every email your AI sends, and validate agent-generated content – sender, recipients, body, headers, attachments, spam score – from a single API.
-
/projects/{project_id}/sandboxes
Create hosted sandboxes that capture email instead of delivering it.
-
/sandboxes/{sandbox_id}/messages/{message_id}/mail_headers
Returns all email headers as key-value pairs.
-
/send/{sandbox_id}
Send a test email to your sandbox.
-
/sandboxes/{sandbox_id}/messages/{message_id}
Inspect captured messages, attachments, spam score, and HTML analysis.
Copy
curl -X POST https://mailtrap.io/api/projects/{project_id}/sandboxes \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"sandbox": {
"name": "My Test Sandbox"
}
}'
Test email directly from Claude, Cursor, and VS Code
Expose Mailtrap Sandbox as MCP tools so agents can send test emails, inspect results, and validate output without writing API code.
Copy
{
"mcpServers": {
"mailtrap": {
"command": "npx",
"args": ["-y", "mcp-mailtrap"],
"env": {
"MAILTRAP_API_TOKEN": "your_mailtrap_api_token",
"DEFAULT_FROM_EMAIL": "your_sender@example.com",
"MAILTRAP_ACCOUNT_ID": "your_account_id",
"MAILTRAP_TEST_INBOX_ID": "your_test_inbox_id"
}
}
}
}
Why test your agent's emails
AI agents don't produce the same output every time. A sandbox lets you review what they can actually generate before a real recipient sees it.
-
Catch agent mistakes before they ship
Review every email your agent generates before it reaches a real recipient.
- Catch hallucinated content and wrong recipients
- Review the full message before delivery
- Compare output against expected behavior
-
Verify what your workflow sends
Whether your AI runs in Zapier, n8n, custom code, or anywhere else, route the email it generates to Sandbox first and check what came out.
- Inspect every email before your workflow moves on
- Check spam score, HTML, and content automatically
- Detect regressions after prompt or model changes
-
Add human approval when needed
When your logic determines a message needs human review, preview it in Sandbox first. Once approved, switch to live sending.
- Review drafts before sending
- Flip from sandbox to live
- Keep autonomous workflows under control
Built for teams testing AI-generated email
Whether you're building agents, internal applications, or automation workflows, Agent Email Sandbox helps you test email safely before it reaches real recipients.
-
AI builders & enthusiasts
Test what your agent would send before it goes live.
- Validate agent-generated replies
- Compare outputs across prompts and model versions
- Iterate fast without spamming real inboxes
-
Engineering teams
Add inbound email to internal systems, databases, support tools, and workflows.
- Add inbound email to your internal apps and automations
- Save each parsed message to your database after fetching it from the Messages API
- Use a hosted address to get started, then move to your own custom domain for production
-
SMBs & customer-facing businesses
Use email as an event source for automation pipelines, approvals, routing, and notifications.
- Kick off pipelines and jobs as soon as an email arrives
- Spin up and tear down disposable sandboxes per workflow, all via API
- Isolate dev, staging, and production on separate sandboxes
Common use cases for Agent Email Sandbox
What teams build with agent sandboxes
AI agent quality testing
Inspect every email your agent drafts and catch the bad ones before a customer sees them.
AI workflow integration
Drop the sandbox into agent and automation pipelines to validate output end-to-end.
Customer-facing automation (SMB)
Put a safety net under the automated emails your business sends to real customers.
Inbound reply testing
Test how your agent replies to inbound emails before those replies ever go out.
Human-in-the-loop
Require a person to sign off before any agent-generated email leaves the sandbox.
Connect with the tools your team already uses
Add sandbox into your stack. Trigger tests from CI, push captured messages to your eval framework, queues, or databases, and reach it over the native connectors, API, or MCP.
Supabase
Vercel
Claude Code
Mailtrap MCP Server
Cursor
Google Antigravity
Frequently Asked Questions
-
What is an email sandbox for AI agents?
It’s a safe, Mailtrap-hosted environment that captures the email your AI agent sends instead of delivering it. Your agent sends exactly as it would in production but every message lands in the sandbox, where you can read the content, headers, and attachments, check the spam score, and validate the HTML. Nothing reaches a real recipient, so you can test what an agent generates without any risk of emailing a customer by mistake.
-
Do test emails ever reach real people?
No. By default, everything your agent sends to a sandbox stays in the sandbox. If you do need to send a specific message to a real address – for example, to share an approved draft — you can forward it to a recipient you’ve confirmed in advance. Otherwise nothing leaves the Email Sandbox.
-
Can my agent drive the sandbox over MCP?
Yes. With the Mailtrap MCP server added to your editor, your agent can send test emails, pull and search captured messages, read their content and headers, and check spam score and HTML — all as natural-language tool calls, without you writing API plumbing.
-
How is this different from the inbound agent inbox?
The agent inbox is about email coming in — your agent receives a message, parses it, and reacts. The sandbox is about email going out. If your agent uses Inbound in production, route its outbound replies to Sandbox during dev — you’ll see exactly what gets sent back before any real recipient does.
-
Can I create a separate sandbox for each agent or test run?
Yes. Organize sandboxes under projects and create or delete them through the API, so each agent, environment, or test run gets its own isolated sandbox. That keeps one agent’s test mail from mixing with another’s, and lets you spin up a fresh sandbox for a run and tear it down the moment it finishes.
-
Can my agent reply to emails from the sandbox?
No. Sandbox is designed for safe email testing and review, not for sending emails to recipients.
To send a real email, use Mailtrap Email Sending API or SMTP. If you’re working with inbound emails, use the Inbound Reply API to respond within the original thread.
The APIs are designed to work together, making it easy to preview an AI-generated email in Sandbox first and then send the approved version through the appropriate sending endpoint.
-
How do I add a human-in-the-loop approval step to my AI email workflow?
A common approach is to have your AI agent generate emails in Mailtrap Sandbox first instead of sending them directly.
You can review the message in the Mailtrap UI or retrieve its content, spam score, HTML checks, and other analysis via API. If changes are needed, your AI agent can revise the draft and send an updated version to Sandbox for another review cycle.
Once the email looks right, switch to Mailtrap’s sending endpoint (or the Inbound Reply API for inbound conversations) to deliver the final message. This creates a simple human approval workflow without changing your email generation logic.