Skip to main content
Run the StateSet iCommerce engine in a Cloudflare Sandboxwrangler deploy and you have a full commerce engine with messaging channels, MCP tools, and an admin UI.

Architecture

A Worker deployment is reachable from the internet the moment it is published. Configure Cloudflare Access before you deploy, not after — the admin UI below ships with the Worker, and an unprotected deployment exposes commerce data to anyone who finds the URL.

Requirements

Free-tier Cloudflare features used:
  • Cloudflare Access (authentication)
  • AI Gateway (optional, for API routing/analytics)
  • R2 Storage (optional, for persistence)

Quick Start

After deploying, your commerce engine is live at https://stateset-sandbox.your-subdomain.workers.dev/. The first request takes 1-2 minutes while the container boots. A loading page is shown during startup. To use the admin UI and protected routes, you’ll need to:
  1. Set up Cloudflare Access for authentication
  2. Enable R2 storage so commerce data persists (recommended)

Setting Up Cloudflare Access

The admin UI at /_admin/ and all /api/admin/* routes require Cloudflare Access authentication.

1. Enable Access on workers.dev

  1. Go to the Workers & Pages dashboard
  2. Select your Worker (stateset-sandbox)
  3. In Settings > Domains & Routes, click the ... menu on the workers.dev row
  4. Click Enable Cloudflare Access
  5. Configure who can access (email allow list, Google, GitHub, etc.)
  6. Copy the Application Audience (AUD) tag

2. Set Access Secrets

Find your team domain in the Zero Trust Dashboard under Settings > Custom Pages.

3. Redeploy

Now /_admin/ requires Cloudflare Access authentication.

Persistent Storage (R2)

By default, commerce data (SQLite database, config) is lost when the container restarts. R2 storage enables persistence.

Setup

  1. Go to R2 > Overview in the Cloudflare Dashboard
  2. Click Manage R2 API Tokens
  3. Create a token with Object Read & Write permissions for the stateset-data bucket

How It Works

SQLite backup — The commerce database is backed up safely using SQLite’s built-in .backup API, which handles concurrent writes correctly. A cron job runs every 5 minutes. Config sync — Gateway configuration is synced to R2 via rsync. Restore on boot — On container startup, data is restored from R2 if the backup is newer than local data. An integrity check verifies the database before restoring. Manual backup — Trigger an immediate backup from the admin UI Storage tab or via POST /api/admin/storage/sync.

Admin UI

Access the admin UI at /_admin/ with three tabs:
  • Overview — Gateway status, commerce stats (customers, orders, returns, products), channel summary, restart controls
  • Channels — Per-channel status cards for all 6 messaging channels (Telegram, Discord, Slack, WhatsApp, Email, SMS)
  • Storage — R2 configuration status, last backup time, manual backup button, backup strategy info

Messaging Channels

Configure channels via environment secrets. Each channel is enabled automatically when its token is set.

Telegram

Discord

Slack

WhatsApp

Email

SMS (Twilio)

Commerce Settings

AI Gateway (Optional)

Route API requests through Cloudflare AI Gateway for caching, rate limiting, and analytics:
AI Gateway variables take precedence over direct ANTHROPIC_API_KEY if both are set.

Container Lifecycle

By default, the container stays alive indefinitely. To sleep after inactivity (reduces cost, adds cold start latency):
With R2 configured, data persists across restarts.

Debug Endpoints

Enable with DEBUG_ROUTES=true (requires Cloudflare Access):

Local Development

Set DEV_MODE=true in .dev.vars to skip Cloudflare Access auth.

All Secrets Reference

* One of ANTHROPIC_API_KEY or AI_GATEWAY_API_KEY is required.

Troubleshooting

Container fails to start: Check npx wrangler tail for logs. Verify ANTHROPIC_API_KEY is set. R2 not mounting: Ensure all three secrets are set (R2_ACCESS_KEY_ID, R2_SECRET_ACCESS_KEY, CF_ACCOUNT_ID). R2 mounting only works in production. Access denied on admin routes: Verify CF_ACCESS_TEAM_DOMAIN and CF_ACCESS_AUD are set correctly. Slow first request: Cold starts take 1-2 minutes. A loading page is shown automatically. Config changes not working: Update the Dockerfile cache bust comment and redeploy.

Next steps

Cloudflare Access setup

The section below, and the first thing to do.

CLI overview

The same engine, run locally.

iCommerce quickstart

Getting the engine working before deploying it.

Sandbox deployments

Other places the engine runs.
Last modified on August 29, 2026