Skip to content

Commit 76da539

Browse files
motatoesMohamed Habib
andauthored
Add Burst Sandbox edge routing (#353)
* Add resumable sandbox edge routing * Route Burst Sandboxes through edge * Allow variable sizes for Burst edge route * Update wrangler.prod.toml --------- Co-authored-by: Mohamed Habib <mohamedhabib@Mohameds-MacBook-Pro.local>
1 parent b5249b3 commit 76da539

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

cloudflare-workers/api-edge/src/index.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ export interface Env extends DashboardEnv {
3333
// CF_API_TOKEN and CF_ZONE_ID are optional in DashboardEnv (custom domain
3434
// feature gates on them). Inherited.
3535
ASSETS?: Fetcher;
36+
// Optional alpha Burst Sandbox cell. When unset, burst=true creates
37+
// fail closed rather than silently landing on on-demand capacity.
38+
BURST_CELL_ID?: string;
3639
}
3740

3841
// ── small helpers ────────────────────────────────────────────────────────
@@ -440,18 +443,43 @@ async function createSandbox(req: Request, env: Env): Promise<Response> {
440443

441444
// Read body once — used for size-gating, the hard-pin cell peek, and the
442445
// verbatim forward to the CP.
443-
const bodyText = await req.text();
446+
let bodyText = await req.text();
444447
let requestedCellID: string | null = null;
445448
let bodyCpuCount = 0;
446449
let bodyMemoryMB = 0;
447450
let bodyDiskMB = 0;
451+
let burst = false;
448452
try {
449453
if (bodyText) {
450-
const parsed = JSON.parse(bodyText) as { cellId?: unknown; cpuCount?: unknown; memoryMB?: unknown; diskMB?: unknown };
454+
const parsed = JSON.parse(bodyText) as {
455+
cellId?: unknown;
456+
cpuCount?: unknown;
457+
memoryMB?: unknown;
458+
diskMB?: unknown;
459+
burst?: unknown;
460+
image?: unknown;
461+
snapshot?: unknown;
462+
};
451463
if (typeof parsed.cellId === "string") requestedCellID = parsed.cellId;
452464
if (typeof parsed.cpuCount === "number") bodyCpuCount = parsed.cpuCount;
453465
if (typeof parsed.memoryMB === "number") bodyMemoryMB = parsed.memoryMB;
454466
if (typeof parsed.diskMB === "number") bodyDiskMB = parsed.diskMB;
467+
if (typeof parsed.burst === "boolean") burst = parsed.burst;
468+
469+
if (burst) {
470+
if (!env.BURST_CELL_ID) {
471+
return json({ error: "Burst Sandboxes alpha is not configured" }, 503);
472+
}
473+
if (requestedCellID && requestedCellID !== env.BURST_CELL_ID) {
474+
return json({ error: "burst cannot be combined with a different cellId" }, 400);
475+
}
476+
if (parsed.image != null || parsed.snapshot != null) {
477+
return json({ error: "Burst Sandboxes do not support image or snapshot creates in alpha" }, 400);
478+
}
479+
parsed.burst = true;
480+
requestedCellID = env.BURST_CELL_ID;
481+
bodyText = JSON.stringify(parsed);
482+
}
455483
}
456484
} catch {
457485
/* malformed JSON — let the CP reject with a proper 400 */

cloudflare-workers/api-edge/wrangler.prod.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ WORKER_ENV = "prod"
6262
# No prod cells registered yet. Populate when prod CPs come online and
6363
# their rows are written to the D1 `cells` table.
6464
CELLS = ""
65+
# Optional alpha route for Burst Sandboxes. Leave empty to disable.
66+
BURST_CELL_ID = "aws-us-east-2-burst-prod"
6567

6668
# Ship Worker logs to opencomputer-log-tail-prod → Axiom dataset cf-prod.
6769
[[tail_consumers]]

cloudflare-workers/api-edge/wrangler.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ WORKER_ENV = "dev"
9494
# the D1 `cells` table (see schema.sql + scripts/seed_dev_xcell.sh).
9595
# Cross-cell testbed: dev2 (Azure westus2) + dev3 (AWS us-east-1).
9696
CELLS = "azure-us-west-2-b,aws-us-east-1-a"
97+
# Optional alpha route for Burst Sandboxes. Leave empty to disable.
98+
BURST_CELL_ID = ""
9799

98100
# Ship console output + exceptions to opensandbox-log-tail, which forwards
99101
# to Axiom dataset cf-dev. Keeps CF Worker logs durable in the same store

0 commit comments

Comments
 (0)