Skip to content
Tinbox

tutorials

From zero to a running inbox with npx tinbox init

October 14, 2026

#tinbox#quickstart#cloudflare#self-hosting#tutorial
A message moves from dispatch through a check to a recipient tray.

Standing up a full email stack usually means a week of glue: a sender, a webmail UI, a marketing tool, a database, attachment storage, and an inbound parser, each with its own account and bill. This walkthrough collapses that into one command and explains exactly what it scaffolds.

A normal "build your own email" project means picking a transactional API, a separate marketing tool, a webmail frontend, somewhere to store attachments, a database for messages, and an inbound parser, then writing the glue that holds all of them together. Each piece is a separate account, a separate SDK, and a separate line on your bill. npx tinbox init exists to skip that assembly: one Worker, one Cloudflare account, your domain. Here is the whole flow end to end, including what the bootstrapper writes to disk and the one step it deliberately cannot do for you.

What does npx tinbox init actually do?

npx tinbox init <domain> copies a project template that ships inside the tinbox package, stamps it to your domain and a derived org slug, installs dependencies, and prints the exact commands to provision and deploy. It does not call Cloudflare. Provisioning is a separate, idempotent step (tinbox setup), so scaffolding stays fast, offline, and deterministic. If you want the condensed version first, the five steps from npx tinbox init to your first sent email is the short path, and the things to know before you run npx tinbox init flags the decisions worth making up front.

Run it:

npx tinbox init acme.com

If you omit the domain in an interactive terminal, it prompts for one. If you pass a domain, it runs straight through with no prompts, which is what makes it scriptable for an agent or CI. The early output tells you everything it derived:

  domain:     acme.com
  org:        acme  (derived from domain)
  deploy at:  tinbox.acme.com
  template:   cloudflare-basic
  dir:        /home/you/acme

▸ Scaffold
  copied 8 files
  stamped: tinbox.config.ts, wrangler.jsonc, package.json, README.md

▸ Install

Two things to notice. The org (acme) is a lowercase-dash slug derived from the domain. It scopes every Cloudflare resource as tinbox-acme-*, so many tenants can live on one Cloudflare account without name collisions. Override it with -o, --org <id> if the default is wrong (for example, two brands on the same apex). The deploy host defaults to tinbox.<domain>, a custom-domain route the Worker claims on deploy. The domain's zone must already be on this Cloudflare account.

What files does the scaffold write?

The cloudflare-basic template is eight files, and only one of them is yours to edit regularly: tinbox.config.ts, the master config. The Worker entry just hands it to createWorker():

// src/worker.ts is boilerplate. Edit tinbox.config.ts, not this file.
import { createWorker } from "tinbox/cf";
import config from "../tinbox";

export default createWorker(config);

createWorker(config) builds the full deployment from one object: the inbox API (tRPC) plus the React inbox UI, authentication (email/password and optional GitHub OAuth), the AI assistant when a provider key is present, attachment streaming, and the MCP endpoint that external agents connect to. The config itself is small and readable after stamping:

// tinbox.config.ts is the one file you edit to configure this instance.
import type { TinboxConfig } from "tinbox/cf/types";

const config: TinboxConfig = {
  org: "acme",                      // scopes Cloudflare resources as tinbox-acme-*
  domains: ["acme.com"],            // first is primary; others are aliases
  deployHost: "tinbox.acme.com",    // where this Worker lives

  features: {
    chat: true,        // needs ANTHROPIC_API_KEY or OPENAI_API_KEY
    campaigns: true,   // needs the NEWSLETTER_QUEUE binding
    githubAuth: true,  // needs GITHUB_CLIENT_ID + GITHUB_CLIENT_SECRET
  },
};

export default config;

The domains array accepts more than one entry, but be honest about the limit: one deploy serves one brand/domain in practice today. Multi-domain-per-instance is designed but not built. If you run several brands, run several deploys on the same Cloudflare account; that is what the tinbox-<org>-* scoping is for.

The heavy lifting lives in wrangler.jsonc, which the scaffold also stamps. It declares the single Worker as both producer and consumer of its own queues (campaign fan-out and inbound projection), a cron trigger whose scheduled() runs due campaigns and automation ticks, and the assets block that serves the prebuilt UI:

{
  "name": "tinbox-acme",
  "main": "src/worker.ts",
  "routes": [{ "pattern": "tinbox.acme.com", "custom_domain": true }],

  "d1_databases": [
    {
      "binding": "DB",
      "database_name": "tinbox-acme-db",
      "database_id": "REPLACE_WITH_D1_DATABASE_ID",
      "migrations_dir": "node_modules/tinbox/migrations"
    }
  ],
  "r2_buckets": [{ "binding": "BLOBS", "bucket_name": "tinbox-acme-mail" }],
  "kv_namespaces": [{ "binding": "KV", "id": "REPLACE_WITH_KV_NAMESPACE_ID" }],

  "assets": {
    "directory": "./node_modules/tinbox/public",
    "binding": "ASSETS",
    "run_worker_first": ["/api/*", "/health", "/attachments/*", "/signed-asset", "/mcp"],
    "not_found_handling": "single-page-application"
  }
}

Notice the REPLACE_WITH_* placeholders. Those are the resource IDs you do not have yet, and they are exactly what tinbox setup fills in. The migrations and the built inbox SPA both ship inside node_modules/tinbox, so there is no build-and-copy step in your project: migrations_dir and the assets directory point straight into the package.

How do I provision Cloudflare and deploy?

First authenticate Cloudflare, then run tinbox setup. There are two auth paths, one for humans and one for agents:

cd acme

# A human, interactive OAuth:
wrangler login

# Or an agent / CI, no browser:
export CLOUDFLARE_API_TOKEN=...      # token with Workers, D1, R2, KV, Queues scopes
export CLOUDFLARE_ACCOUNT_ID=...

Then provision and deploy in one idempotent command:

pnpm tinbox:setup --deploy
# or, equivalently from anywhere in the project:
tinbox setup --deploy

tinbox setup creates the D1 database (tinbox-acme-db), the R2 bucket (tinbox-acme-mail), the KV namespace, and the queues (tinbox-acme-newsletter, its dead-letter queue, and tinbox-acme-projection). It writes the real resource IDs back into wrangler.jsonc, generates strong secrets into a gitignored .env.prod, pushes them with wrangler secret put, applies the bundled migrations, and (with --deploy) ships the Worker. The whole thing is safe to re-run: it only does what is still missing, so a half-finished run resumes cleanly.

One ordering wrinkle worth knowing: wrangler secret put needs the Worker to exist first, so setup deploys before pushing secrets. If you ever run it without --deploy and then try to set secrets, you will see this:

! BETTER_AUTH_SECRET: worker not deployed yet.
  Run `pnpm tinbox:deploy` once, then `tinbox setup` again to push secrets.

The fix is in the message: deploy once, then re-run setup. When it finishes you get:

  🎉  Deployed! Open your worker URL to create the first account.
  Next: tinbox doctor to confirm status.

tinbox doctor is a read-only status report: it tells you what is authenticated, which resources exist, which secrets are set, and which version you are on. Run it any time you are unsure where a deploy stalled.

The secrets to know about: BETTER_AUTH_SECRET is required for auth and is auto-generated. ANTHROPIC_API_KEY or OPENAI_API_KEY powers the AI assistant. ASSET_SIGNING_KEY signs attachment URLs. GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET enable GitHub OAuth. TINBOX_LICENSE_KEY is the optional lifetime license; nothing is blocked if it is absent (the free build runs in production with a soft, honor-system nag).

How does inbound email get into the inbox?

After deploy you add one routing rule in the Cloudflare dashboard, because inbound mail routing is account-level and cannot be set in wrangler.jsonc. The Worker already has an email() handler; Cloudflare just has to be told to forward mail to it:

Cloudflare dashboard
  → acme.com → Email → Email Routing → Enable
  → Add a catch-all rule:
       "Send to a Worker" → tinbox-acme

That is the deliberate manual step. Everything else is automated, but Cloudflare keeps inbound routing as an explicit, account-scoped decision, and there is no API surface in the Worker config to claim it. One reason this stack lives on Cloudflare at all is the other direction: Workers cannot open outbound port 25 for direct-to-MX SMTP, so outbound mail goes over an HTTPS-based sender rather than classic SMTP. Inbound, by contrast, rides Cloudflare Email Routing straight into your Worker. The fuller case for the platform is in the reasons to run your email stack on Cloudflare.

For the catch-all and address mechanics in more depth, see setting up a catch-all that routes every address to one Worker, and the steps to receive inbound email on your own Cloudflare account for the same routing path walked end to end.

How do I run it locally and ship updates?

Run the Worker locally with wrangler dev, and ship new versions with one resumable command. Local development needs no Cloudflare provisioning:

pnpm tinbox:dev
# Worker runs at http://localhost:8787

When you upgrade the package or pull changes, the update flow installs, migrates, and redeploys in order, and is idempotent:

pnpm update tinbox
pnpm tinbox:update    # install → migrate → deploy

There is also pnpm tinbox:limits, which checks the build stays inside Workers size limits without deploying. That matters because the whole stack (API, UI, migrations, AI agent) ships as one Worker, and you want to catch a bundle that crept over the limit before a deploy fails.

Doing this the hard way (and why you might still)

If you wanted to assemble the same capabilities by hand, the honest shopping list is roughly: a transactional sender API and a marketing/newsletter tool (two products, two bills, often Resend plus Mailchimp), a webmail or inbox UI you build or host, an object store for attachments, a database with full-text search for messages, an inbound parser wired to Cloudflare Email Routing or a third-party inbound endpoint, an auth system, and, if you want an AI agent over the mailbox, an LLM integration plus an MCP server with its own OAuth. Each integration is a weekend, and the per-email pricing on the managed pieces compounds as you grow.

That assembly is a legitimate choice, and sometimes the right one. If you need a single best-in-class deliverability vendor with a dedicated IP and a support contract, a managed sender earns its price. If you are comparing the managed route honestly, the trade-offs of a self-hosted sender versus Resend and how per-email pricing actually adds up at volume are the two posts to read before you decide, and the tools for building serverless email on Cloudflare survey the pieces you would otherwise wire together by hand.

npx tinbox init is the "or skip all of this" path: one command scaffolds the project, one idempotent command provisions and deploys it, and one dashboard rule routes mail in. The result runs on your own Cloudflare account, the data lives in your own D1 and R2, and the bill is Cloudflare's metered usage with no per-email tier. You give up the hand-holding and a managed support contract, and you own the deliverability work yourself. For an indie hacker already on Cloudflare, that trade is usually the easy one.

For the bigger picture of where this fits, start at the Tinbox overview and what one deploy includes.

Deploy this yourself: npx tinbox init <domain>. Full command reference and the bundled template live in the docs.

Frequently asked questions

What does npx tinbox init actually do?

It copies a bundled project template (no git clone, works offline), stamps it to your domain and a derived org slug, installs dependencies, and prints the next commands. It does not touch Cloudflare. Provisioning D1, R2, KV, and queues is the job of tinbox setup, which runs separately and is idempotent.

Does npx tinbox init deploy to Cloudflare by itself?

By default, tinbox init scaffolds and then runs the provision-and-deploy step (tinbox setup --deploy) when Cloudflare credentials are available. Pass --no-deploy to stop after scaffold and install, then run tinbox setup yourself. Either way init never invents Cloudflare resources without setup; setup is what creates the D1 database, R2 bucket, KV namespace, and queues.

How is the inbox served if there is no separate frontend deploy?

The built React inbox UI ships inside the tinbox npm package and is served from Workers Assets. wrangler.jsonc points the assets directory at ./node_modules/tinbox/public, with run_worker_first keeping the API, auth, attachment, and MCP routes on the Worker. There is no separate build or copy step in your project.

Why do I still have to click something in the Cloudflare dashboard for inbound email?

Inbound mail routing is account-level configuration that cannot be set in wrangler.jsonc. After deploy you enable Email Routing on your domain and add a catch-all rule that sends to the Worker (tinbox-<org>). The Worker has an email() handler ready, but Cloudflare has to be told to forward mail to it.

What is the org slug and where does it come from?

The org is a lowercase-dash slug that scopes every Cloudflare resource as tinbox-<org>-*. tinbox init derives it from your domain (acme.com becomes acme), so many tenants can share one Cloudflare account without name collisions. You can override it with --org. One deploy serves one brand/domain; multi-domain-per-instance is designed but not built yet.