Skip to main content
A preview URL is a public HTTPS endpoint that routes traffic to a port inside your sandbox. Start a web server, create a preview URL, and share the link.
import { 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.preview.opencomputer.dev

API Reference

Create Preview URL

const preview = await sandbox.createPreviewURL({
  port: 3000,
  domain: "preview.myapp.com", // optional custom domain
});
ParameterTypeRequiredDescription
portnumberYesContainer port to expose (1–65535)
domainstringNoCustom domain
authConfigobjectNoAuthentication configuration

List Preview URLs

const previews = await sandbox.listPreviewURLs();
for (const p of previews) {
  console.log(`Port ${p.port}: https://${p.hostname}`);
}

Delete Preview URL

await sandbox.deletePreviewURL(3000);

Custom Domains

Pass a 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.

Persistence

Preview URLs persist across hibernation and wake cycles. If you hibernate a sandbox and wake it later, the preview URLs are still active.

Multiple Ports

Expose multiple services from the same sandbox:
// Frontend
await sandbox.createPreviewURL({ port: 3000 });
// API server
await sandbox.createPreviewURL({ port: 8080 });
// Database admin
await sandbox.createPreviewURL({ port: 5432 });
CLI equivalent: oc preview. Full reference: TypeScript SDK · Python SDK · HTTP API.