All Topics
All Topics
Technology
Technology
AI
AI
Business
Business
Entertainment
Entertainment
News
News
Programming
Programming
Security
Security
Science
Science
Design
Design
Environment
Environment
Finance
Finance
Crypto
Crypto
Politics
Politics
Sports
Sports
Education
Education
Gaming
Gaming
Art
Art
Music
Music
Health
Health
Books
Books
Food
Food
Travel
Travel
Personal
Personal
Bluesky
Twitter

Agents - Share sandbox previews through Cloudflare Tunnel

1mo ago

Source

CloudflareAgents - Share sandbox previews through Cloudflare Tunnelcloudflare.com
Snippet from the RSS feed
Sandboxes can expose a service running inside the container on a public preview URL through the sandbox.tunnels namespace. The SDK uses cloudflared inside the sandbox so you can share a running service without configuring exposePort() or a custom domain. By default, sandbox.tunnels.get(port) creates a quick tunnel on a zero-config *.trycloudflare.com URL — no Cloudflare account, DNS record, or custom domain required. This is perfect for quick development and for .workers.dev deployments. JavaScript import { getSandbox } from "@cloudflare/sandbox" ; const sandbox = getSandbox ( env . Sandbox , "my-sandbox" ) ; await sandbox . startProcess ( "python -m http.server 8080" ) ; const tunnel = await sandbox . tunnels . get ( 8080 ) ; console . log ( tunnel . url ) ; // → TypeScript import { getSandbox } from "@cloudflare/sandbox" ; const sandbox = getSandbox ( env . Sandbox , "my-sandbox" ) ; await sandbox . startProcess ( "python -m http.server 8080" ) ; const tunnel = await sandbox . tunnels . get ( 8080 ) ; console . log ( tunnel . url ) ; // → Named tunnels For more control you can create a named tunnel through sandbox.tunnels.get(port, { name }) . A named tunnel binds a hostname ( . ) backed by a Cloudflare Tunnel and a CNAME record on your zone resulting in something like . Unlike quick tunnels, which generate a new random URL each time, a named tunnel produces a persistent URL that survives container restarts. This makes named tunnels suitable for production use cases where you want control over the tunnel and it's origin. JavaScript const tunnel = await sandbox . tunnels . get ( 8080 , { name : "my-app-preview" } ) ; console . log ( tunnel . url ) ; // → TypeScript const tunnel = await sandbox . tunnels . get ( 8080 , { name : "my-app-preview" } ) ; console . log ( tunnel . url ) ; // → Calling sandbox.destroy() tears down the Cloudflare Tunnel and the associated DNS record alongside the container, so you do not leave dangling tunnels or records behind. Upgrade To update to the latest version: npm i @cloudflare/sandbox@latest yarn add @cloudflare/sandbox@latest pnpm add @cloudflare/sandbox@latest bun add @cloudflare/sandbox@latest For full API details, refer to the Sandbox tunnels reference .

You might also wanna read

Comments

Sign in to join the conversation.

No comments yet. Be the first.