caelum0x b5e772f51c feat: replace Cloudflare Access gate with Scribase owner-only auth
Cloudflare Access was permanently blocking this Worker (500 Cloudflare
Access must be configured in production): Zero Trust was never enabled
on the account and no available credential had Access-write scope.
Instead of waiting on that credential, access control now lives in code
against Scribase (this portfolio's self-hosted, Supabase-compatible
auth backend): a request is let through only if its Scribase access
token resolves to the exact OWNER_EMAIL account.

- workers/lib/scribase-auth.ts: token extraction, remote verification
  via GET /auth/v1/user, sign-in/refresh/sign-out via the password and
  refresh_token grants, with 25 unit tests.
- workers/lib/login-page.ts: dependency-free HTML sign-in page.
- workers/app.ts: new middleware (fail-closed on missing config, silent
  refresh-token retry, uniform 401 for API/MCP callers vs redirect for
  HTML), /login (rate-limited via a native Workers ratelimits binding)
  and /logout (also revokes the session server-side) routes. Removes
  the old jose/JWKS Cloudflare Access check entirely.
- wrangler.jsonc, .dev.vars.example, workers/types.ts, README.md:
  SCRIBASE_URL/SCRIBASE_ANON_KEY/OWNER_EMAIL replace
  POLICY_AUD/TEAM_DOMAIN; jose dropped from package.json.

Reviewed by code-reviewer and security-reviewer subagents; every
MEDIUM/HIGH finding fixed. Deployed and verified live: the Worker now
fails closed with the new Scribase message instead of the old
Cloudflare one. Provisioning the actual Scribase project is blocked on
a one-time $1 card check on the Scribase org (owner-only payment
action) -- see NOTES.md and ~/products/plans/agentic-inbox.md.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-24 17:10:54 +03:00

Agentic Inbox

A self-hosted email client with an AI agent, running entirely on Cloudflare Workers

Agentic Inbox lets you send, receive, and manage emails through a modern web interface -- all powered by your own Cloudflare account. Incoming emails arrive via Cloudflare Email Routing, each mailbox is isolated in its own Durable Object with a SQLite database, and attachments are stored in R2.

An AI-powered Email Agent can read your inbox, search conversations, and draft replies -- built with the Cloudflare Agents SDK and Workers AI.

Agentic Inbox screenshot

Read the blog post to learn more about Cloudflare Email Service and how to use it with the Agents SDK, MCP, and from the Wrangler CLI: Email for Agents.

How to setup

Important: Clicking the 'Deploy to Cloudflare' button is only one part of the setup. You must follow the After deploying steps as well. For a full step-by-step guide with screenshots, refer to this comment: https://github.com/cloudflare/agentic-inbox/issues/4#issuecomment-4269118513

To set up

  1. Deploy to Cloudflare. The deploy flow will automatically provision R2, Durable Objects, and Workers AI. You'll be prompted for DOMAINS, which is the domain (yourdomain.com) you want to receive emails for (email@yourdomain.com).

    Deploy to Cloudflare

  2. Configure Scribase auth -- This fork authenticates against Scribase (a self-hosted, Supabase-compatible auth/db backend) instead of Cloudflare Access. Create a Scribase project with email/password sign-in enabled, then set SCRIBASE_URL and OWNER_EMAIL in wrangler.jsonc vars and SCRIBASE_ANON_KEY as a Worker secret (wrangler secret put SCRIBASE_ANON_KEY). Only the account whose email matches OWNER_EMAIL can sign in; every other Scribase account is refused even if its credentials are valid.

  3. Set up Email Routing -- In the Cloudflare dashboard, go to your domain > Email Routing and create a catch-all rule that forwards to this Worker

  4. Enable Email Service -- The worker needs the send_email binding to send outbound emails. See Email Service docs

  5. Create a mailbox -- Visit your deployed app and create a mailbox for any address on your domain (e.g. hello@example.com)

Troubleshooting auth

  1. If you see Scribase auth must be configured in production, this application is intentionally refusing to serve any request until SCRIBASE_URL, SCRIBASE_ANON_KEY and OWNER_EMAIL are all set, so your inbox is not exposed to anyone on the internet.
    • Resolution: provision a Scribase project with email/password sign-in, then set the three values above and redeploy.
  2. If /login shows Invalid email or password, either the credentials are wrong or they belong to an account other than OWNER_EMAIL -- both cases are reported identically on purpose, so a non-owner account can't be used to probe which email is configured.
  3. Sessions are two httpOnly cookies (sb-access-token, sb-refresh-token). The access token is refreshed silently in the background; if both expire or are revoked, you're redirected back to /login.

Features

  • Full email client — Send and receive emails via Cloudflare Email Routing with a rich text composer, reply/forward threading, folder organization, search, and attachments
  • Per-mailbox isolation — Each mailbox runs in its own Durable Object with SQLite storage and R2 for attachments
  • Built-in AI agent — Side panel with 9 email tools for reading, searching, drafting, and sending
  • Auto-draft on new email — Agent automatically reads inbound emails and generates draft replies, always requiring explicit confirmation before sending
  • Configurable and persistent — Custom system prompts per mailbox, persistent chat history, streaming markdown responses, and tool call visibility

Stack

  • Frontend: React 19, React Router v7, Tailwind CSS, Zustand, TipTap, @cloudflare/kumo
  • Backend: Hono, Cloudflare Workers, Durable Objects (SQLite), R2, Email Routing
  • AI Agent: Cloudflare Agents SDK (AIChatAgent), AI SDK v6, Workers AI (@cf/moonshotai/kimi-k2.5), react-markdown + remark-gfm
  • Auth: Scribase (self-hosted, Supabase-compatible) owner-only sign-in, validated against /auth/v1/user (required outside local development)

Getting Started

npm install
npm run dev

Configuration

  1. Set your domain in wrangler.jsonc
  2. Create an R2 bucket named agentic-inbox: wrangler r2 bucket create agentic-inbox

Deploy

npm run deploy

Prerequisites

  • Cloudflare account with a domain
  • Email Routing enabled for receiving
  • Email Service enabled for sending
  • Workers AI enabled (for the agent)
  • A Scribase project with email/password sign-in enabled, and its own account for the owner (SCRIBASE_URL, SCRIBASE_ANON_KEY, OWNER_EMAIL configured for deployed/shared environments; required in production)

Only the Scribase account matching OWNER_EMAIL can access this app by design. This includes the MCP server at /mcp -- external AI tools (Claude Code, Cursor, etc.) connected via MCP can operate on any mailbox by passing a mailboxId parameter, once authenticated the same way. There is no per-mailbox authorization; the owner-only auth gate is the single trust boundary.

Architecture

┌──────────────┐     ┌──────────────────┐     ┌─────────────────┐
│   Browser    │────>│  Hono Worker     │────>│  MailboxDO      │
│  React SPA   │     │  (API + SSR)     │     │  (SQLite + R2)  │
│  Agent Panel │     │                  │     └─────────────────┘
└──────┬───────┘     │  /agents/* ──────┼────>┌─────────────────┐
       │             │                  │     │  EmailAgent DO  │
       │ WebSocket   │                  │     │  (AIChatAgent)  │
       └─────────────┤                  │     │  9 email tools  │
                     │                  │────>│  Workers AI     │
                     └──────────────────┘     └─────────────────┘

License

Apache 2.0 -- see LICENSE.

Description
A self-hosted email client with an AI agent, running entirely on Cloudflare Workers
Readme Pixar 3.6 MiB
Languages
TypeScript 99.9%
CSS 0.1%