{"id":518,"date":"2026-05-29T00:00:00","date_gmt":"2026-05-29T00:00:00","guid":{"rendered":"https:\/\/wordpress.securinsight.ca\/index.php\/2026\/05\/29\/agents-share-sandbox-previews-through-cloudflare-tunnel\/"},"modified":"2026-05-29T00:00:00","modified_gmt":"2026-05-29T00:00:00","slug":"agents-share-sandbox-previews-through-cloudflare-tunnel","status":"publish","type":"post","link":"https:\/\/wordpress.securinsight.ca\/index.php\/2026\/05\/29\/agents-share-sandbox-previews-through-cloudflare-tunnel\/","title":{"rendered":"Agents &#8211; Share sandbox previews through Cloudflare Tunnel"},"content":{"rendered":"<p><a href=\"https:\/\/developers.cloudflare.com\/sandbox\/\">Sandboxes<\/a> can expose a service running inside the container on a public preview URL through the <code>sandbox.tunnels<\/code> namespace. The SDK uses <code>cloudflared<\/code> inside the sandbox so you can share a running service without configuring <code>exposePort()<\/code> or a custom domain.<\/p>\n<p>By default, <code>sandbox.tunnels.get(port)<\/code> creates a <a href=\"https:\/\/try.cloudflare.com\/\" target=\"_blank\">quick tunnel<\/a> on a zero-config <code>*.trycloudflare.com<\/code> URL \u2014 no Cloudflare account, DNS record, or custom domain required. This is perfect for quick development and for <code>.workers.dev<\/code> deployments.<\/p>\n<ul>\n<li>\n<p>JavaScript<\/p>\n<div>\n<div>\n<figure>\n<pre data-language=\"js\"><code class=\"language-js\"><div><div><span>import <\/span><span>{<\/span><span><span> <\/span><span>getSandbox<\/span><span> <\/span><\/span><span>}<\/span><span> from <\/span><span>\"@cloudflare\/sandbox\"<\/span><span>;<\/span><\/div><\/div><div><div>\n<\/div><\/div><div><div><span>const<\/span><span> <\/span><span>sandbox<\/span><span> <\/span><span>=<\/span><span> <\/span><span>getSandbox<\/span><span>(<\/span><span>env<\/span><span>.<\/span><span>Sandbox<\/span><span>,<\/span><span> <\/span><span>\"my-sandbox\"<\/span><span>)<\/span><span>;<\/span><\/div><\/div><div><div><span>await<\/span><span> <\/span><span>sandbox<\/span><span>.<\/span><span>startProcess<\/span><span>(<\/span><span>\"python -m http.server 8080\"<\/span><span>)<\/span><span>;<\/span><\/div><\/div><div><div>\n<\/div><\/div><div><div><span>const<\/span><span> <\/span><span>tunnel<\/span><span> <\/span><span>=<\/span><span> <\/span><span>await<\/span><span> <\/span><span>sandbox<\/span><span>.<\/span><span>tunnels<\/span><span>.<\/span><span>get<\/span><span>(<\/span><span>8080<\/span><span>)<\/span><span>;<\/span><\/div><\/div><div><div><span>console<\/span><span>.<\/span><span>log<\/span><span>(<\/span><span>tunnel<\/span><span>.<\/span><span>url<\/span><span>)<\/span><span>;<\/span><span> <\/span><span>\/\/ \u2192 https:\/\/random-words-here.trycloudflare.com<\/span><\/div><\/div><\/code><\/pre>\n<div>\n<div><\/div>\n<\/div>\n<\/figure>\n<\/div><\/div>\n<\/li>\n<li>\n<p>TypeScript<\/p>\n<div>\n<div>\n<figure>\n<pre data-language=\"ts\"><code class=\"language-ts\"><div><div><span>import <\/span><span>{<\/span><span><span> <\/span><span>getSandbox<\/span><span> <\/span><\/span><span>}<\/span><span> from <\/span><span>\"@cloudflare\/sandbox\"<\/span><span>;<\/span><\/div><\/div><div><div>\n<\/div><\/div><div><div><span>const<\/span><span> <\/span><span>sandbox<\/span><span> <\/span><span>=<\/span><span> <\/span><span>getSandbox<\/span><span>(<\/span><span>env<\/span><span>.<\/span><span>Sandbox<\/span><span>,<\/span><span> <\/span><span>\"my-sandbox\"<\/span><span>)<\/span><span>;<\/span><\/div><\/div><div><div><span>await<\/span><span> <\/span><span>sandbox<\/span><span>.<\/span><span>startProcess<\/span><span>(<\/span><span>\"python -m http.server 8080\"<\/span><span>)<\/span><span>;<\/span><\/div><\/div><div><div>\n<\/div><\/div><div><div><span>const<\/span><span> <\/span><span>tunnel<\/span><span> <\/span><span>=<\/span><span> <\/span><span>await<\/span><span> <\/span><span>sandbox<\/span><span>.<\/span><span>tunnels<\/span><span>.<\/span><span>get<\/span><span>(<\/span><span>8080<\/span><span>)<\/span><span>;<\/span><\/div><\/div><div><div><span>console<\/span><span>.<\/span><span>log<\/span><span>(<\/span><span>tunnel<\/span><span>.<\/span><span>url<\/span><span>)<\/span><span>;<\/span><span> <\/span><span>\/\/ \u2192 https:\/\/random-words-here.trycloudflare.com<\/span><\/div><\/div><\/code><\/pre>\n<div>\n<div><\/div>\n<\/div>\n<\/figure>\n<\/div><\/div>\n<\/li>\n<\/ul>\n<h4>Named tunnels<\/h4>\n<p>For more control you can create a named tunnel through <code>sandbox.tunnels.get(port, { name })<\/code>. A named tunnel binds a hostname (<code>&lt;name&gt;.&lt;your-zone&gt;<\/code>) backed by a <a href=\"https:\/\/developers.cloudflare.com\/cloudflare-one\/networks\/connectors\/cloudflare-tunnel\/\">Cloudflare Tunnel<\/a> and a CNAME record on your zone resulting in something like <a href=\"https:\/\/my-app-preview.example.com\/\" target=\"_blank\">https:\/\/my-app-preview.example.com<\/a>.<\/p>\n<p>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&#8217;s origin.<\/p>\n<ul>\n<li>\n<p>JavaScript<\/p>\n<div>\n<div>\n<figure>\n<pre data-language=\"js\"><code class=\"language-js\"><div><div><span>const<\/span><span> <\/span><span>tunnel<\/span><span> <\/span><span>=<\/span><span> <\/span><span>await<\/span><span> <\/span><span>sandbox<\/span><span>.<\/span><span>tunnels<\/span><span>.<\/span><span>get<\/span><span>(<\/span><span>8080<\/span><span>,<\/span><span> <\/span><span>{<\/span><span> name<\/span><span>:<\/span><span> <\/span><span>\"my-app-preview\"<\/span><span> <\/span><span>}<\/span><span>)<\/span><span>;<\/span><\/div><\/div><div><div><span>console<\/span><span>.<\/span><span>log<\/span><span>(<\/span><span>tunnel<\/span><span>.<\/span><span>url<\/span><span>)<\/span><span>;<\/span><span> <\/span><span>\/\/ \u2192 https:\/\/my-app-preview.example.com<\/span><\/div><\/div><\/code><\/pre>\n<div>\n<div><\/div>\n<\/div>\n<\/figure>\n<\/div><\/div>\n<\/li>\n<li>\n<p>TypeScript<\/p>\n<div>\n<div>\n<figure>\n<pre data-language=\"ts\"><code class=\"language-ts\"><div><div><span>const<\/span><span> <\/span><span>tunnel<\/span><span> <\/span><span>=<\/span><span> <\/span><span>await<\/span><span> <\/span><span>sandbox<\/span><span>.<\/span><span>tunnels<\/span><span>.<\/span><span>get<\/span><span>(<\/span><span>8080<\/span><span>,<\/span><span> <\/span><span>{<\/span><span> name<\/span><span>:<\/span><span> <\/span><span>\"my-app-preview\"<\/span><span> <\/span><span>}<\/span><span>)<\/span><span>;<\/span><\/div><\/div><div><div><span>console<\/span><span>.<\/span><span>log<\/span><span>(<\/span><span>tunnel<\/span><span>.<\/span><span>url<\/span><span>)<\/span><span>;<\/span><span> <\/span><span>\/\/ \u2192 https:\/\/my-app-preview.example.com<\/span><\/div><\/div><\/code><\/pre>\n<div>\n<div><\/div>\n<\/div>\n<\/figure>\n<\/div><\/div>\n<\/li>\n<\/ul>\n<p>Calling <code>sandbox.destroy()<\/code> tears down the Cloudflare Tunnel and the associated DNS record alongside the container, so you do not leave dangling tunnels or records behind.<\/p>\n<h4>Upgrade<\/h4>\n<p>To update to the latest version:<\/p>\n<div>\n<div>  <\/div>\n<div>\n<div>\n<pre><code class=\"astro-qph66ij4\"><span>npm<\/span><span> i @cloudflare\/sandbox@latest<\/span><\/code><\/pre>\n<\/div>\n<\/div>\n<div>\n<div>\n<pre><code class=\"astro-qph66ij4\"><span>yarn<\/span><span> add @cloudflare\/sandbox@latest<\/span><\/code><\/pre>\n<\/div>\n<\/div>\n<div>\n<div>\n<pre><code class=\"astro-qph66ij4\"><span>pnpm<\/span><span> add @cloudflare\/sandbox@latest<\/span><\/code><\/pre>\n<\/div>\n<\/div>\n<div>\n<div>\n<pre><code class=\"astro-qph66ij4\"><span>bun<\/span><span> add @cloudflare\/sandbox@latest<\/span><\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>For full API details, refer to the <a href=\"https:\/\/developers.cloudflare.com\/sandbox\/api\/tunnels\/\">Sandbox tunnels reference<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>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 \u2014 no Cloudflare account, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-518","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/posts\/518","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/comments?post=518"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/posts\/518\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/media?parent=518"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/categories?post=518"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/tags?post=518"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}