Skip to content

RFC: sandbox-on-demand via x402 (sats-denominated, AIBTC-gated) #108

@whoabuddy

Description

@whoabuddy

TL;DR

  • Pay x402 → get a Cloudflare Sandbox provisioned per-Stacks-address, ticking down a sats-denominated credit bucket per second of wall-clock uptime.
  • sBTC is the primary settlement token (1:1 sats, no oracle). STX/USDCx supported via a multi-source price oracle. Bucket holds one unit: sats.
  • AIBTC-gated at create/extend via aibtc-genesis-gate: caller proves control of both BTC + Stacks keys (Bitcoin signature + SIP-018), and aibtc.com confirms the pair is registered at level ≥ 2 (Genesis).
  • Settlement rides x402-sponsor-relay; receipts use @aibtc/tx-schemas PAYMENT_STATES. No inline x402 settle.
  • Lifecycle: alive → grace (60s, receipt-extending, 10min hard cap) → reaped. DO state and ledger persist across reaps; only the Cloudflare sandbox handle dies.

Why this fits in x402-api

This repo is increasingly the agent-survival service — inference, storage, hashing, stacks tools — all priced in sats, all paid from the agent's own wallet. Sandbox-on-demand closes the loop: an agent inside a sandbox can pay for its own downstream services from the same address that funded the sandbox. A single Stacks wallet bootstraps a self-sustaining agent.

Inspiration: conway.tech (pay-as-you-go compute, USD-denominated) and agentslovebitcoin.com (per-AIBTC-agent service pattern). We diverge from conway by denominating in sats, not cents.

Proposed phasing

  1. Phase 0 — Spike. Throwaway worker exercising @cloudflare/sandbox@0.9.2 directly. Output: real numbers for idle/active $/min, cold start, destroy() semantics, OOM behavior, native-supervisor presence. Drives the sats_per_second rate. (1-day target.)
  2. Phase 1 — SandboxDO + create / extend / status / reap. Wall-clock metering, manual tick verification, sBTC + STX payments, settlement via relay.
  3. Phase 2 — Proxy. /sandbox/proxy/* forwards into the sandbox; per-call x402 from external clients.
  4. Phase 3 — Self-paying agent. Boot template with encrypted-wallet-on-disk + treasury caps; sample agent calls our inference endpoints from inside.
  5. Phase 4 — AIBTC integration. Resolve aibtc.com agent handle → Stacks address → sandbox; one-click "wake my agent" UX.
  6. Phase 5 — CPU/request metering, full multi-token rate oracle, refund policy, dispute log.

Three open work streams (good first issues for collaborators)

  • Stream 1 — Phase 0 spike. Throwaway worker, @cloudflare/sandbox@0.9.2, measure real numbers. Deliverable: phase-0-findings.md. Blocks Phase 1.
  • Stream 2 — Image deep-dive. Compare aibtcdev/agent-runtime vs aibtcdev/loop-starter-kit on size, dep graph, MCP integration, wallet-pattern fit, cold-start contribution. Picks the curated default boot image. Independent of Stream 1.
  • Stream 3 — aibtc-genesis-gate org migration. Move arc0btc/aibtc-genesis-gate under aibtcdev/, set up OIDC publish workflow, cut v0.1.0 on npm. Async coordination work. Phase 1 pins to github SHA in the meantime; only the npm dep swap blocks on this.

Asks for reviewers

  • Sanity-check the sats-only bucket thesis. Multi-token only at ingress; everything internal in sats. Aggressive simplification — flag if it breaks something I didn't see.
  • Sanity-check the identity gating (BTC sig + SIP-018 + genesis-gate pair check at level ≥ 2). Strictly stronger than "match x402 payer to gate stxAddress" but more complex — worth it?
  • Reaper grace policy (60s default, payment-receipt extension, 10min hard cap) — is the cap right? Too lenient? Too tight?
  • Identity check at create/extend only (Q4c) — comfortable with progression-only assumption, or should every status check re-verify?
  • MCP exposure (Q20) — happy with surfacing the broader x402-api tool suite as first-class MCP tools alongside the new sandbox ones?

Full design

All 20 open questions resolved 2026-04-29. Full doc (565 lines, schema, lifecycle, settlement, oracle, SpaceX five-step audit, etc.) lives as a gist:

https://gist.github.com/whoabuddy/183304ebeb7779e008cfab6333b45d69

(Local copy is at .planning/2026-04-28-sandbox-on-demand/DESIGN.md, which is gitignored.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions