domain property that gives you instant access to port 80 without creating a preview URL explicitly:123456789const sandbox = await Sandbox.create(); await sandbox.exec.run("python3 -m http.server 80 &"); console.log(sandbox.domain); // → sb-abc123-p80.workers.opencomputer.dev // For other ports: console.log(sandbox.getPreviewDomain(3000)); // → sb-abc123-p3000.workers.opencomputer.dev
domain and getPreviewDomain(port) properties construct the preview hostname directly — no API call needed. Traffic is routed through the control plane proxy to the correct sandbox.previewAuth.Authorization: Bearer <token> (or X-OC-Preview-Token: <token>) header on every preview-URL request. Missing or wrong → 401. The check happens before traffic ever reaches your sandbox, so a brute-force run also can't wake a hibernated sandbox.1234567const sandbox = await Sandbox.create({ previewAuth: { scheme: "bearer", token: "auto" }, }); // previewAuthToken is returned exactly once — store it somewhere durable. console.log(sandbox.previewAuthToken); // → "qx2sSi5IYXWBvnnRqwK9Ky_cIAI-x0Vx1bPCt0XMxsI"
token: "auto" (or omitting the field) tells the server to generate a 256-bit random token. To bring your own — useful when your gateway already has a secret it can share with both ends — pass an explicit string of at least 16 characters:123await Sandbox.create({ previewAuth: { scheme: "bearer", token: process.env.GATEWAY_TOKEN! }, });
12curl -H "Authorization: Bearer $TOKEN" https://sb-abc123-p3000.workers.opencomputer.dev/ curl -H "X-OC-Preview-Token: $TOKEN" https://sb-abc123-p3000.workers.opencomputer.dev/
rotate. The old token stops working immediately and the new plaintext is returned exactly once:12const newToken = await sandbox.rotatePreviewAuthToken(); // sandbox.previewAuthToken is also updated in place.
previewAuth has open preview URLs — exactly the same as before this feature existed. The feature is fully opt-in and backwards compatible.12345678import { Sandbox } from "@opencomputer/sdk"; const sandbox = await Sandbox.create(); await sandbox.exec.run("npx create-next-app@latest /app --yes", { timeout: 120 }); sandbox.exec.start("npm run dev -- --port 3000", { cwd: "/app" }); const preview = await sandbox.createPreviewURL({ port: 3000 }); console.log(preview.hostname); // sb-abc123-p3000.workers.opencomputer.dev
1234const preview = await sandbox.createPreviewURL({ port: 3000, domain: "preview.myapp.com", // optional custom domain });
| Parameter | Type | Required | Description |
port | number | Yes | Container port to expose (1–65535) |
domain | string | No | Custom domain |
authConfig | object | No | Authentication configuration |
1234const previews = await sandbox.listPreviewURLs(); for (const p of previews) { console.log(`Port ${p.port}: https://${p.hostname}`); }
1await sandbox.deletePreviewURL(3000);
domain when creating a preview URL. SSL is provisioned automatically via Cloudflare. Custom domain verification is configured at the organization level through the dashboard — not through the SDK.123456// Frontend await sandbox.createPreviewURL({ port: 3000 }); // API server await sandbox.createPreviewURL({ port: 8080 }); // Database admin await sandbox.createPreviewURL({ port: 5432 });