Retrieved article excerpt
Open article Β· Retrieved 2026-10-28T11:28:01.757371+00:00
# Nuvrail
**The approval layer between AI agents and your inbox.**
[Demo: an AI agent's bulk delete is staged by Nuvrail and rejected with one tap; the mailbox is untouched.](https://github.com/agens-field/nuvrail/blob/main/docs/assets/3am-demo/3am-demo.gif)
*An agent tries to delete 38 emails at 3am. Nothing happens until a human says yes.*
The agent's `EXPUNGE` gets `OK Noted` and is never forwarded; the staged delete is rejected with one tap.
Recorded in CI against a local test mail server; the "agent" is a short script, and any IMAP client behaves the same through the proxy.
[Reproduce it yourself](https://github.com/agens-field/nuvrail/blob/main/docs/assets/3am-demo/README.md) Β· [MP4 (67 s)](https://github.com/agens-field/nuvrail/blob/main/docs/assets/3am-demo/3am-demo.mp4)
[License: AGPL v3](https://github.com/agens-field/nuvrail/blob/main/LICENSE)
[Self-host](https://github.com/agens-field/nuvrail#-try-it-in-60-seconds-local)
[PRs welcome](https://github.com/agens-field/nuvrail/blob/main/CONTRIBUTING.md)
[Stars](https://github.com/agens-field/nuvrail/stargazers)
> Email is the most dangerous thing you can hand an AI agent. Nuvrail makes it safe to try β
> reads flow through instantly, every write waits for one human tap. **If that sounds useful,
> [β
star the repo](https://github.com/agens-field/nuvrail) and [self-host it in 60 seconds](https://github.com/agens-field/nuvrail#-try-it-in-60-seconds-local).**
AI agents that can send email are useful. AI agents that can send email *without any human check* are a liability. Nuvrail sits between your AI agent and your real mail server. The agent sees a normal IMAP/SMTP server. Every write β every move, delete, flag change, and outbound send β is staged for your approval before it touches the real mailbox. Reads pass through instantly; nothing blocks the agent from working. Only destructive or irreversible actions require a human to say yes.
---
## How it works
```
AI agent Nuvrail Real mail server
ββββββββ IMAP/SMTP βββββββ IMAP/SMTP ββββββββββββββββ
(Claude, βββββββββββββββΊ gateway βββββββββββββββΊ (Gmail, iCloud,
Cursor, reads: pass β on approval Outlook, or any
custom) through β only IMAP/SMTP server)
instantly β
writes: staged
β human reviews
& approves
```
1. **Agent writes a command** β e.g. `UID MOVE 42 Trash` or sends an email via SMTP.
2. **Gateway intercepts it** β returns `OK [STAGED]` immediately so the agent can keep working.
3. **You get a notification** β a push notification on your phone or browser shows you exactly what the agent wants to do, with the subject, sender, and destination.
4. **You approve or reject** β one tap. On approval the operation executes against the real server. On rejection the proxy reverts its local state and silently surfaces the rejection to the agent on its next command.
The agent can never permanently delete mail. `EXPUNGE` is blocked at the gateway layer, and a delete (`\Deleted`) is staged like any other write β the worst the agent can do is ask to delete a message, and even that requires your sign-off.
> π **Why this exists:** [Why email is the most dangerous thing you can give an AI agent](https://github.com/agens-field/nuvrail/blob/main/docs/why-email-is-dangerous.md) β
> the failure modes, why scoped OAuth and read-only tokens don't close them, and why the fix belongs on the wire.
>
> π§ **Guides:** [Stop an AI agent from deleting your emails](https://github.com/agens-field/nuvrail/blob/main/docs/guides/stop-ai-agent-deleting-emails.md) Β·
> [Add human approval before an AI agent sends email](https://github.com/agens-field/nuvrail/blob/main/docs/guides/human-approval-before-ai-agent-sends-email.md) Β·
> [Human in the loop for LLM email agents](https://github.com/agens-field/nuvrail/blob/main/docs/guides/human-in-the-loop-llm-email-agent.md)
**Wiring up a specific agent?** Step-by-step recipes: [Claude Desktop](https://github.com/agens-field/nuvrail/blob/main/docs/integrations/claude-desktop.md) Β·
[Cursor](https://github.com/agens-field/nuvrail/blob/main/docs/integrations/cursor.md) Β· [LangChain](https://github.com/agens-field/nuvrail/blob/main/docs/integrations/langchain.md).
---
## β‘ Try it in 60 seconds (local)
Just want to see it work? You need **Docker with the Compose plugin** β nothing else. No
domain, no TLS, no nginx. This runs everything on `localhost` for evaluation.
```
git clone https://github.com/agens-field/nuvrail.git
cd nuvrail
cp .env.example .env
docker compose up --build
```
> π **Port 3000 already taken?** Set `NUVRAIL_HOST_WEB_PORT=3400` in `.env`
> (likewise `NUVRAIL_HOST_API_PORT`, `NUVRAIL_HOST_IMAP_PORT`, `NUVRAIL_HOST_SMTP_PORT`)
> and use that port in the URLs below. Ports are published host-side only β nothing
> about the host or port is baked into the web bundle, so `docker compose up -d` picks
> the change up without a rebuild.
> β±οΈ **First build takes several minutes β this is normal, not a hang.** The initial
> `--build` compiles both images from scratch (Python deps for the gateway, a Vite build
> for the web PWA), so a true fresh clone with a cold cache is typically **~5β9 min** on
> first run β not 60 seconds. Later `docker compose up` runs start in seconds. If the
> terminal sits quiet mid-build, it is compiling, not stuck; let it finish.
Sign-up is **closed by default** (`NUVRAIL_SIGNUP_MODE=closed`), so the web app has no
"create account" button. Create your first account from the CLI once the containers are up
(it prompts for a password):
```
docker compose exec gateway python3 scripts/manage_users.py create [email protected] --name "You"
```
Then open **<http://localhost:3000>** and log in. (Prefer self-serve sign-up? See
[Account creation](https://github.com/agens-field/nuvrail#account-creation-signup-modes).) The API is on
`http://localhost:8080`:
```
# Give the containers ~10β20s after the build finishes to come up healthy,
# then this returns {"status": "ok", ...}. A connection-refused here just
# means the gateway is still starting β wait a moment and retry.
curl -s http://localhost:8080/health # β {"status": "ok", ...}
```
That's it β the approval UI, REST API, and IMAP/SMTP proxies (`localhost:10143` / `localhost:10587`)
are all running. Point a test IMAP/SMTP client at the proxy ports and watch writes get staged for
approval in the UI.
> π **Running it on a remote box?** The browser never calls the API directly β
> the web container proxies `/api/` to the gateway over the compose network β so only
> the web port needs publishing. Set `NUVRAIL_BIND_ADDR=0.0.0.0` in `.env`, rerun
> `docker compose up -d`, and open `http://<host>:3000`. No rebuild, no `VITE_API_URL`,
> no CORS entry. Do this on a trusted network only: it is plain HTTP carrying bearer
> tokens β see [Deploying to production](https://github.com/agens-field/nuvrail#deploying-to-production) for the TLS path.
> βΉοΈ **Local trial only.** With `NUVRAIL_MASTER_KEY` left blank the gateway auto-generates a
> key on first run (fine for kicking the tires, **not** for real mail). To connect a real
> mailbox with agents on other machines, follow [Deploying to production](https://github.com/agens-field/nuvrail#deploying-to-production)
> below β that adds TLS, nginx, and a persisted master key.
Like what you see? **[β
Star the repo](https://github.com/agens-field/nuvrail)** β it's the
fastest way to help other people find it.
---
## Architecture
```
Internet
β
ββββΊ :993 IMAPS βββΊ nginx (TLS) βββΊ IMAP proxy (10143) βββΊ upstream IMAP
ββββΊ :465 SMTPS βββΊ nginx (TLS) βββΊ SMTP proxy (10587) βββΊ upstream SMTP
ββββΊ :443 HTTPS βββΊ nginx (TLS) βββΊ Web PWA + REST API (3000/8080)
All external TLS terminates at nginx. Docker containers are bound to 127.0.0.1 only.
No plain-text port is reachable from outside the host.
```
**Components:**
- **IMAP proxy** (`gateway/proxy.py`) β asyncio IMAP4rev1 state machine. Intercepts writes, passes reads, maintains a local SQLite mirror for optimistic consistency.
- **SMTP proxy** (`gateway/smtp_proxy.py`) β asyncio. Intercepts `DATA` (outbound sends), stages them. Relays on approval.
- **Staging engine** (`gateway/staging.py`) β assigns op IDs, stores snapshots for revert, tracks 48-hour expiry.
- **REST API** (`api/`) β FastAPI. Approve/reject operations, manage agents, audit log, push subscriptions.
- **Web PWA** (`web/`) β React 18 + Vite + TypeScript + Tailwind. Login, pending operations, audit log, agent management. Installable as a PWA on iOS/Android.
**Key design constraints:**
- Standard IMAP/SMTP on both ends β no agent modifications required
- EXPUNGE and CLOSE never forwarded; `\Deleted` is staged for approval like any other write
- AES-256-GCM for all credentials at rest; TLS everywhere in transit
- Push payloads are end-to-end encrypted to your device (Web Push, RFC 8291), so the push relay never sees email metadata
- Immutable audit log β every action is recorded forever
---
## Deploying to production
The 60-second path above is for evaluation on `localhost`. To run Nuvrail as a real service β
reachable by an agent on another machine, terminating TLS, connecting a real mailbox β follow
the full deployment below.
### Prerequisites
- Ubuntu 22.04 LTS (or equivalent Debian-based distro)
- DNS `A` record pointing at your server:
- `nuvrail.example.com` β server IP (approval UI + proxy)
- Git, Docker Engine + Compose plugin, nginx with stream module, certbot
```
# Docker Engine
curl -fsSL https://get.docker.com | sh
sudo usermod -aG docker $USER # log out and back in
# nginx with stream module + certbot
sudo apt install -y nginx libnginx-mod-stream certbot python3-certbot-nginx
```
---
### Step 1 β Clone and configure
```
sudo mkdir -p /opt/nuvrail && sudo chown $USER:$USER /opt/nuvrail
git clone https://github.com/agens-field/nuvrail.git /opt/nuvrail
cd /opt/nuvrail
cp .env.example .env
nano .env
```
Required environment variables:
| Variable | Description |
| --- | --- |
| `NUVRAIL_MASTER_KEY` | 64 hex chars β `python3 -c "import secrets; print(secrets.token_bytes(32).hex())"` |
| `NUVRAIL_CORS_ORIGINS` | `https://nuvrail.example.com` |
| `NUVRAIL_SIGNUP_MODE` | Who may create accounts: `closed` (default), `invite`, or `open`. See [Account creation](https://github.com/agens-field/nuvrail#account-creation-signup-modes). |
| `NUVRAIL_ALLOW_OPEN_SIGNUP` | Required ack (`1`) **only** when `NUVRAIL_SIGNUP_MODE=open`; the API refuses to start with `open` unless this is set. |
| `NUVRAIL_VAPID_EMAIL` | Admin contact email, e.g. `mailto:[email protected]` |
| `GOOGLE_CLIENT_ID` | GCP OAuth2 client ID (required for Gmail agent setup) |
| `GOOGLE_CLIENT_SECRET` | GCP OAuth2 client secret (required for Gmail agent setup) |
| `GOOGLE_REDIRECT_URI` | `https://nuvrail.example.com/api/v1/oauth2/google/callback` |
| `MICROSOFT_CLIENT_ID` | Azure AD app client ID (required for Outlook/O365 agent setup) |
| `MICROSOFT_CLIENT_SECRET` | Azure AD app client secret (required for Outlook/O365 agent setup) |
| `MICROSOFT_REDIRECT_URI` | `https://nuvrail.example.com/api/v1/oauth2/microsoft/callback` |
| `MICROSOFT_TENANT` | Azure AD tenant β `common` (default) for personal + multi-tenant, or a tenant GUID/domain for single-tenant |
> β οΈ **Back up `NUVRAIL_MASTER_KEY`.** It encrypts every upstream credential in the
> database. Losing it makes all stored agent credentials unrecoverable.
**Choose your signup mode now** β it decides who can create an account on this
deployment and it is fail-closed, so a fresh `.env` is already private. Pick one
and put the matching lines in `.env`:
```
# closed (DEFAULT) β no public sign-up; you provision users from the admin CLI.
# This is also what you get if you set nothing at all. Best for a private /
# single-tenant instance.
NUVRAIL_SIGNUP_MODE=c