OpenAICloudflare Developer PlatformMay 29, 2026, 12:00 AM

Agents - Share sandbox previews through Cloudflare Tunnel

A condensed section focused on the key takeaways first.

Original Post

Quick Digest

Summary

A condensed section focused on the key takeaways first.

openaienmodel: gpt-5-mini-2025-08-07

Agents - Share sandbox previews through Cloudflare Tunnel

Key Points

  • Zero-config *.trycloudflare.com previews
  • Persistent named tunnels with CNAME support
  • Tunnels and DNS torn down on sandbox.destroy()

Summary

Cloudflare Sandbox now exposes containerized services through Cloudflare Tunnel (using cloudflared) so you can share public preview URLs without configuring exposePort() or a custom domain. By default sandbox.tunnels.get(port) returns a zero‑config quick tunnel on a *.trycloudflare.com URL for fast dev previews; use a named tunnel (sandbox.tunnels.get(port, { name })) to bind a persistent hostname on your zone backed by a Cloudflare Tunnel and CNAME.

Key Points

  • Zero‑config quick tunnels: sandbox.tunnels.get(port) → random-words.trycloudflare.com; no Cloudflare account or DNS changes required.
  • Named tunnels: sandbox.tunnels.get(port, { name }) creates a persistent hostname (name.your-zone) with a Cloudflare Tunnel + CNAME; survives container restarts.
  • Cleanup: calling sandbox.destroy() tears down the Cloudflare Tunnel and removes the associated DNS record to avoid dangling resources.
  • Use cases: quick developer previews, sharing running services, and .workers.dev deployments.

Quick examples

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);
// → https://random-words-here.trycloudflare.com
// Named tunnel (persistent hostname)
const named = await sandbox.tunnels.get(8080, { name: "my-app-preview" });
console.log(named.url);
// → https://my-app-preview.example.com

Upgrade

Install the latest SDK to get tunnels:

npm i @cloudflare/sandbox@latest

Notes

  • Quick tunnels are ideal for ephemeral previews; use named tunnels for stable preview domains.
  • sandbox.destroy() removes both the tunnel and DNS record automatically.

Full Translation

Translations

A translation section that keeps the flow of the original article.

openaijamodel: gpt-5-mini-2025-08-07

Agents - Cloudflare Tunnel を使ってサンドボックスのプレビューを共有

Agents — Cloudflare Tunnel を使ってサンドボックスのプレビューを共有

公開日: 2026-05-29

サンドボックスはコンテナ内で動作するサービスを公開プレビュー用の URL で公開できます。sandbox.tunnels 名前空間を使うと、SDK がサンドボックス内で cloudflared を利用しているため、exposePort() やカスタムドメインの設定なしで実行中のサービスを共有できます。既定では、sandbox.tunnels.get(port) はゼロコンフィグの *.trycloudflare.com URL を使ったクイックトンネルを作成します — Cloudflare アカウント、DNS レコード、カスタムドメインは不要です。これは素早い開発や .workers.dev 展開に最適です。

クイックトンネルの例

JavaScript / 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 ) ;
// → https://random-words-here.trycloudflare.com

名前付きトンネル (Named tunnels)

より細かい制御が必要な場合は、sandbox.tunnels.get(port, { name }) で名前付きトンネルを作成できます。名前付きトンネルはホスト名(<name>.<your-zone>)を Cloudflare Tunnel とゾーン上の CNAME レコードで紐付け、例えば https://my-app-preview.example.com のようになります。クイックトンネルが毎回ランダムな URL を生成するのに対し、名前付きトンネルはコンテナ再起動後も存続する永続的な URL を生成します。したがって、トンネルとオリジンを制御したい本番に近いユースケースに適しています。

JavaScript / TypeScript の例:

const tunnel = await sandbox . tunnels . get ( 8080 , { name : "my-app-preview" } ) ;
console . log ( tunnel . url ) ;
// → https://my-app-preview.example.com

sandbox.destroy() を呼び出すと、Cloudflare Tunnel と関連する DNS レコードがコンテナとともに削除されるため、トンネルやレコードが残置されることはありません。

アップグレード

最新バージョンに更新するには:

  • npm: npm i @cloudflare/sandbox@latest
  • yarn: yarn add @cloudflare/sandbox@latest
  • pnpm: pnpm add @cloudflare/sandbox@latest
  • bun: bun add @cloudflare/sandbox@latest

詳細な API は Sandbox tunnels reference を参照してください。


その他のリソース: API、Directory、Sponsorships、Open Source、Cloudflare Research、Help Center、System Status など。