AutoClaw
← Examples

openclaw-aaas

OpenClaw AaaS

Managed service for running template-based OpenClaw agents with:

This repository is a monorepo with a web control plane and a Cloudflare Worker API.

Product Overview

OpenClaw AaaS is designed for teams that want to ship agent workflows without building platform infrastructure first.

Core idea:

Repository Layout

Architecture

Frontend (apps/web):

Backend (apps/worker-api):

Cloudflare Mapping

This is how OpenClaw Autopilot components map to Cloudflare infrastructure:

Product ComponentCloudflare PrimitivePurpose
API layer (apps/worker-api)WorkersHandles auth, tenant config, Telegram pairing, runs, and webhook endpoints
Persistent app dataD1 (DB)Stores tenants, accounts/sessions, pairing state, runs, and subscription state
Async run executionQueues (RUN_QUEUE)Decouples request/response from run processing and retries
Agent runtime coordinationDurable Objects (AGENT_SESSION)Keeps per-agent execution/session state consistent
Artifacts/output storageR2 (ARTIFACTS)Stores run artifacts and generated output blobs
Model provider abstractionAI GatewayRoutes BYOK model calls with provider-agnostic observability
Billing events ingressWorker webhook (/api/webhooks/stripe)Receives Stripe subscription lifecycle updates
Telegram ingressWorker webhook (/api/telegram/webhook)Receives chat updates and forwards to tenant-scoped execution

High-level flow:

  1. User uses apps/web UI at autoclaw.sh (or your own deployment).
  2. Next.js API routes proxy requests to Worker API (WORKER_API_BASE_URL).
  3. Worker validates auth/session and writes state to D1.
  4. Long-running work is enqueued to RUN_QUEUE.
  5. Queue consumer invokes AgentSession and model calls (AI Gateway/BYOK), then persists run status/results.

Shared Telegram + Tenant Runtime Architecture

The product uses one shared Telegram bot. Tenant isolation is handled by pairing each Telegram user to a tenant, then routing requests into that tenant’s OpenClaw runtime workspace.

flowchart LR
    U[User in Telegram] --> TG[Telegram Platform]
    TG --> WB["Worker API: /api/webhooks/telegram"]

    WB --> PR[(D1: telegram_pairings)]
    PR -->|"telegram_user_id -> tenant_id"| TR[Tenant Router]

    TR --> TT[(D1: tenants)]
    TR --> RT[(D1: tenant_openclaw_runtime)]
    TR --> WS[(R2: tenant/<id>/openclaw/workspace/*)]

    TR --> SB["Cloudflare Sandbox DO: tenant:<tenant_id>"]
    SB --> CT["Cloudflare Container\nOpenClaw Gateway + Workspace (/root/clawd)"]

    CT --> WB
    WB --> TG
    TG --> U

Runtime lifecycle per tenant:

  1. Telegram message hits /api/webhooks/telegram.
  2. Pairing lookup resolves telegram_user_id to tenant_id.
  3. Runtime state is checked in tenant_openclaw_runtime.
  4. If needed, Worker bootstraps workspace files from R2 and starts tenant sandbox/container.
  5. Request is routed to tenant OpenClaw gateway process.
  6. Reply is sent back through Telegram.

Runtime Skills Inventory + Policy

The backend now exposes tenant-scoped runtime skills from the actual OpenClaw sandbox:

This endpoint:

Policy updates are supported with:

Body:

{
  "tenantId": "t_123",
  "policies": [
    { "name": "weather", "allowed": true, "enabled": true, "hidden": false }
  ]
}

Policy semantics:

Diagnostics/remediation:

Telegram command:

Pack semantics:

Request Flow (Happy Path)

  1. UI posts POST /api/control/runs.
  2. Next.js API route proxies to Worker POST /api/runs.
  3. Worker checks tenant subscription status.
  4. Worker writes queued run in D1 and enqueues run payload.
  5. Queue consumer marks run running, optionally calls AI Gateway using BYOK key, invokes AgentSession, then marks run succeeded/failed.

Prerequisites

Getting Started (Developers)

1. Install dependencies

npm install

2. Run web UI locally

npm run dev:web

Open http://localhost:3000.

Optional web env vars:

3. Run Worker API locally

npm run dev:worker

Wrangler config lives at apps/worker-api/wrangler.jsonc.

4. Run backend checks

npm run test:worker
npm run typecheck:worker

5. Build web app

npm run build:web

If Backend Is Already Deployed

You can develop only the UI and point it to deployed backend:

  1. Set WORKER_API_BASE_URL to deployed Worker URL.
  2. Run npm run dev:web.
  3. Use UI pages (/signup, /dashboard, /pricing) against live backend.

Deployment Notes

Frontend:

Backend:

npm run deploy -w apps/worker-api

Security and BYOK

Policy docs:

Current policy intent: