Quick Access
Every sandbox has a built-indomain property that gives you instant access to port 80 without creating a preview URL explicitly:
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.
Authentication
Preview URLs are public by default — anyone who can guess or learn the hostname can hit your sandbox’s port. To require a bearer token in front of every request, opt in at create time withpreviewAuth.
When enabled, the control plane validates an 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.
Enable at create time
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:
Making authenticated requests
Send the token on every request to the preview URL. Two header forms are accepted; pick whichever fits your client:Rotation
When you need to roll the token — exposure, scheduled rotation, employee offboarding — callrotate. The old token stops working immediately and the new plaintext is returned exactly once:
What’s stored and what’s not
- Only the SHA-256 hash of the token is persisted. The server never sees the plaintext after the create or rotate response returns.
- There is no GET endpoint that returns the token. If you lose it, your only options are to rotate (mint a new one) or recreate the sandbox.
- A sandbox created without
previewAuthhas open preview URLs — exactly the same as before this feature existed. The feature is fully opt-in and backwards compatible.
Where the check happens
Authentication is enforced by the cell’s control plane immediately before the request is proxied to the worker. That means:- Hibernated sandboxes stay hibernated on missing/wrong tokens — bad tokens can’t burn wake capacity.
- Self-hosted deployments without the Cloudflare edge get the same gate for free — the check follows the sandbox, not the front door.
Explicit Preview URLs
For tracking, custom domains, or auth configuration, use the preview URL API:API Reference
Create Preview URL
| Parameter | Type | Required | Description |
|---|---|---|---|
port | number | Yes | Container port to expose (1–65535) |
domain | string | No | Custom domain |
authConfig | object | No | Authentication configuration |
List Preview URLs
Delete Preview URL
Custom Domains
Pass adomain 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.