// use cases
Quarantine hostile email before agents read it
Put Context Guardrails between Resend and your agent so phishing, prompt injection, and malicious attachments never enter agent context.
Treat every inbound email as untrusted until it clears Context Guardrails. Resend receives the message, your webhook fetches the raw email, and Superagent checks the sender, body, attachments, and links before your application passes anything to an agent.
Use this verdict policy:
safe— deliver to the agentcaution— hold for reviewsuspiciousordangerous— quarantine
Prerequisites
- A Resend account with a receiving domain
- A Next.js application with a public webhook route
RESEND_API_KEY,RESEND_WEBHOOK_SECRET, andSUPERAGENT_API_KEYstored in the application environment- An existing queue or function that delivers approved email to your agent
1. Receive email with Resend
Open the Receiving tab in Resend and copy the account's .resend.app
address, or configure a custom domain with its required MX record.
Create a webhook in Resend:
- Open Webhooks and select Add Webhook.
- Enter your application's HTTPS route, such as
https://app.example.com/api/webhooks/resend. - Subscribe to
email.received. - Copy the webhook signing secret into
RESEND_WEBHOOK_SECRET.
The email.received payload contains message metadata and an email_id. Fetch
the stored raw message before scanning so Context Guardrails can inspect the
original headers, MIME structure, attachments, HTML, text, and links.
2. Verify and scan the raw email
Create app/api/webhooks/resend/route.ts:
Webhook verification must use request.text() before JSON parsing. Resend
signatures are calculated from the untouched body, so parsing and serializing
the payload before verification invalidates the signature.
mode=full waits for the completed scan. If the receiving platform cannot
wait up to 90 seconds, persist the verified email_id, enqueue processing,
return 202, and run the raw-email fetch and scan in a worker.
3. Deliver only approved email to the agent
Replace the final approved response with the application's existing queue or
agent handoff. Pass rawEmail only from that branch.
Keep the other outcomes separate:
- Send
cautionto a review queue. - Store the scan identifier and verdict for quarantined messages.
- Return
2xxfor reviewed and quarantined messages so Resend does not retry content you intentionally withheld. - Return a retryable error only when signature verification succeeded but the raw email or guardrail service was temporarily unavailable.
The agent should never summarize, reply to, follow links from, or call tools
with an email before the safe verdict.
4. Test the complete email boundary
- Send a Resend webhook test and confirm the signature verifies.
- Send a normal email and confirm it returns
approved. - Send a test message containing an instruction aimed at the agent and confirm
it returns
suspiciousordangerous. - Confirm the unsafe message never enters the agent queue, logs, or prompt.
- Inspect the Context Guardrails result for sender authentication, MIME, attachment, and outbound-link evidence.