{"id":27,"date":"2025-08-05T00:00:00","date_gmt":"2025-08-05T00:00:00","guid":{"rendered":"https:\/\/wordpress.securinsight.ca\/index.php\/2025\/08\/05\/agents-workers-cloudflare-sandbox-sdk-adds-streaming-code-interpreter-git-support-process-control-and-more\/"},"modified":"2025-08-05T00:00:00","modified_gmt":"2025-08-05T00:00:00","slug":"agents-workers-cloudflare-sandbox-sdk-adds-streaming-code-interpreter-git-support-process-control-and-more","status":"publish","type":"post","link":"https:\/\/wordpress.securinsight.ca\/index.php\/2025\/08\/05\/agents-workers-cloudflare-sandbox-sdk-adds-streaming-code-interpreter-git-support-process-control-and-more\/","title":{"rendered":"Agents, Workers &#8211; Cloudflare Sandbox SDK adds streaming, code interpreter, Git support, process control and more"},"content":{"rendered":"<p>We\u2019ve shipped a major release for the <a href=\"https:\/\/github.com\/cloudflare\/sandbox-sdk\" target=\"_blank\">@cloudflare\/sandbox<\/a> SDK, turning it into a full-featured, container-based execution platform that runs securely on Cloudflare Workers.<\/p>\n<p>This update adds live streaming of output, persistent Python and JavaScript code interpreters with rich output support (charts, tables, HTML, JSON), file system access, Git operations, full background process control, and the ability to expose running services via public URLs.<\/p>\n<p>This makes it ideal for building AI agents, CI runners, cloud REPLs, data analysis pipelines, or full developer tools \u2014 all without managing infrastructure.<\/p>\n<h4>Code interpreter (Python, JS, TS)<\/h4>\n<p>Create persistent code contexts with support for rich visual + structured outputs.<\/p>\n<h4>createCodeContext(options)<\/h4>\n<p>Creates a new code execution context with persistent state.<\/p>\n<div>\n<figure>\n<pre data-language=\"ts\"><code class=\"language-ts\"><div><div><span>\/\/ Create a Python context<\/span><\/div><\/div><div><div><span>const<\/span><span> <\/span><span>pythonCtx<\/span><span> <\/span><span>=<\/span><span> <\/span><span>await<\/span><span> <\/span><span>sandbox<\/span><span>.<\/span><span>createCodeContext<\/span><span>(<\/span><span>{<\/span><span> language<\/span><span>:<\/span><span> <\/span><span>\"python\"<\/span><span> <\/span><span>}<\/span><span>)<\/span><span>;<\/span><\/div><\/div><div><div>\n<\/div><\/div><div><div><span>\/\/ Create a JavaScript context<\/span><\/div><\/div><div><div><span>const<\/span><span> <\/span><span>jsCtx<\/span><span> <\/span><span>=<\/span><span> <\/span><span>await<\/span><span> <\/span><span>sandbox<\/span><span>.<\/span><span>createCodeContext<\/span><span>(<\/span><span>{<\/span><span> language<\/span><span>:<\/span><span> <\/span><span>\"javascript\"<\/span><span> <\/span><span>}<\/span><span>)<\/span><span>;<\/span><\/div><\/div><\/code><\/pre>\n<div><\/div>\n<\/figure>\n<\/div>\n<p>Options:<\/p>\n<ul>\n<li>language: Programming language (&#8216;python&#8217; | &#8216;javascript&#8217; | &#8216;typescript&#8217;)<\/li>\n<li>cwd: Working directory (default: \/workspace)<\/li>\n<li>envVars: Environment variables for the context<\/li>\n<\/ul>\n<h4>runCode(code, options)<\/h4>\n<p>Executes code with optional streaming callbacks.<\/p>\n<div>\n<figure>\n<pre data-language=\"ts\"><code class=\"language-ts\"><div><div><span>\/\/ Simple execution<\/span><\/div><\/div><div><div><span>const<\/span><span> <\/span><span>execution<\/span><span> <\/span><span>=<\/span><span> <\/span><span>await<\/span><span> <\/span><span>sandbox<\/span><span>.<\/span><span>runCode<\/span><span>(<\/span><span>'print(\"Hello World\")'<\/span><span>,<\/span><span> <\/span><span>{<\/span><\/div><\/div><div><div><span><span>  <\/span><\/span><span>context<\/span><span>:<\/span><span> <\/span><span>pythonCtx<\/span><span>,<\/span><\/div><\/div><div><div><span>}<\/span><span>)<\/span><span>;<\/span><\/div><\/div><div><div>\n<\/div><\/div><div><div><span>\/\/ With streaming callbacks<\/span><\/div><\/div><div><div><span>await<\/span><span> <\/span><span>sandbox<\/span><span>.<\/span><span>runCode<\/span><span>(<\/span><\/div><\/div><div><div><span>  <\/span><span>`<\/span><\/div><\/div><div><div><span>for i in range(5):<\/span><\/div><\/div><div><div><span><span>    <\/span><\/span><span>print(f\"Step {i}\")<\/span><\/div><\/div><div><div><span><span>    <\/span><\/span><span>time.sleep(1)<\/span><\/div><\/div><div><div><span>`<\/span><span>,<\/span><\/div><\/div><div><div><span>  <\/span><span>{<\/span><\/div><\/div><div><div><span><span>    <\/span><\/span><span>context<\/span><span>:<\/span><span> <\/span><span>pythonCtx<\/span><span>,<\/span><\/div><\/div><div><div><span>    <\/span><span>onStdout<\/span><span>:<\/span><span> <\/span><span>(<\/span><span>output<\/span><span>)<\/span><span> <\/span><span>=&gt;<\/span><span> <\/span><span>console<\/span><span>.<\/span><span>log<\/span><span>(<\/span><span>\"Real-time:\"<\/span><span>,<\/span><span> <\/span><span>output<\/span><span>.<\/span><span>text<\/span><span>)<\/span><span>,<\/span><\/div><\/div><div><div><span>    <\/span><span>onResult<\/span><span>:<\/span><span> <\/span><span>(<\/span><span>result<\/span><span>)<\/span><span> <\/span><span>=&gt;<\/span><span> <\/span><span>console<\/span><span>.<\/span><span>log<\/span><span>(<\/span><span>\"Result:\"<\/span><span>,<\/span><span> <\/span><span>result<\/span><span>)<\/span><span>,<\/span><\/div><\/div><div><div><span>  <\/span><span>},<\/span><\/div><\/div><div><div><span>)<\/span><span>;<\/span><\/div><\/div><\/code><\/pre>\n<div><\/div>\n<\/figure>\n<\/div>\n<p>Options:<\/p>\n<ul>\n<li>language: Programming language (&#8216;python&#8217; | &#8216;javascript&#8217; | &#8216;typescript&#8217;)<\/li>\n<li>cwd: Working directory (default: \/workspace)<\/li>\n<li>envVars: Environment variables for the context<\/li>\n<\/ul>\n<h4>Real-time streaming output<\/h4>\n<p>Returns a streaming response for real-time processing.<\/p>\n<div>\n<figure>\n<pre data-language=\"ts\"><code class=\"language-ts\"><div><div><span>const<\/span><span> <\/span><span>stream<\/span><span> <\/span><span>=<\/span><span> <\/span><span>await<\/span><span> <\/span><span>sandbox<\/span><span>.<\/span><span>runCodeStream<\/span><span>(<\/span><\/div><\/div><div><div><span>  <\/span><span>\"import time; [print(i) for i in range(10)]\"<\/span><span>,<\/span><\/div><\/div><div><div><span>)<\/span><span>;<\/span><\/div><\/div><div><div><span>\/\/ Process the stream as needed<\/span><\/div><\/div><\/code><\/pre>\n<div><\/div>\n<\/figure>\n<\/div>\n<h4>Rich output handling<\/h4>\n<p>Interpreter outputs are auto-formatted and returned in multiple formats:<\/p>\n<ul>\n<li>text<\/li>\n<li>html (e.g., Pandas tables)<\/li>\n<li>png, svg (e.g., Matplotlib charts)<\/li>\n<li>json (structured data)<\/li>\n<li>chart (parsed visualizations)<\/li>\n<\/ul>\n<div>\n<figure>\n<pre data-language=\"ts\"><code class=\"language-ts\"><div><div><span>const<\/span><span> <\/span><span>result<\/span><span> <\/span><span>=<\/span><span> <\/span><span>await<\/span><span> <\/span><span>sandbox<\/span><span>.<\/span><span>runCode<\/span><span>(<\/span><\/div><\/div><div><div><span>  <\/span><span>`<\/span><\/div><\/div><div><div><span>import seaborn as sns<\/span><\/div><\/div><div><div><span>import matplotlib.pyplot as plt<\/span><\/div><\/div><div><div>\n<\/div><\/div><div><div><span>data = sns.load_dataset(\"flights\")<\/span><\/div><\/div><div><div><span>pivot = data.pivot(\"month\", \"year\", \"passengers\")<\/span><\/div><\/div><div><div><span>sns.heatmap(pivot, annot=True, fmt=\"d\")<\/span><\/div><\/div><div><div><span>plt.title(\"Flight Passengers\")<\/span><\/div><\/div><div><div><span>plt.show()<\/span><\/div><\/div><div><div>\n<\/div><\/div><div><div><span>pivot.to_dict()<\/span><\/div><\/div><div><div><span>`<\/span><span>,<\/span><\/div><\/div><div><div><span>  <\/span><span>{<\/span><span> context<\/span><span>:<\/span><span> <\/span><span>pythonCtx<\/span><span> <\/span><span>},<\/span><\/div><\/div><div><div><span>)<\/span><span>;<\/span><\/div><\/div><div><div>\n<\/div><\/div><div><div><span>if<\/span><span> (<\/span><span>result<\/span><span>.<\/span><span>png<\/span><span>) <\/span><span>{<\/span><\/div><\/div><div><div><span><span>  <\/span><\/span><span>console<\/span><span>.<\/span><span>log<\/span><span>(<\/span><span>\"Chart output:\"<\/span><span>,<\/span><span> <\/span><span>result<\/span><span>.<\/span><span>png<\/span><span>)<\/span><span>;<\/span><\/div><\/div><div><div><span>}<\/span><\/div><\/div><\/code><\/pre>\n<div><\/div>\n<\/figure>\n<\/div>\n<h4>Preview URLs from Exposed Ports<\/h4>\n<p>Start background processes and expose them with live URLs.<\/p>\n<div>\n<figure>\n<pre data-language=\"ts\"><code class=\"language-ts\"><div><div><span>await<\/span><span> <\/span><span>sandbox<\/span><span>.<\/span><span>startProcess<\/span><span>(<\/span><span>\"python -m http.server 8000\"<\/span><span>)<\/span><span>;<\/span><\/div><\/div><div><div><span>const<\/span><span> <\/span><span>preview<\/span><span> <\/span><span>=<\/span><span> <\/span><span>await<\/span><span> <\/span><span>sandbox<\/span><span>.<\/span><span>exposePort<\/span><span>(<\/span><span>8000<\/span><span>)<\/span><span>;<\/span><\/div><\/div><div><div>\n<\/div><\/div><div><div><span>console<\/span><span>.<\/span><span>log<\/span><span>(<\/span><span>\"Live preview at:\"<\/span><span>,<\/span><span> <\/span><span>preview<\/span><span>.<\/span><span>url<\/span><span>)<\/span><span>;<\/span><\/div><\/div><\/code><\/pre>\n<div><\/div>\n<\/figure>\n<\/div>\n<h4>Full process lifecycle control<\/h4>\n<p>Start, inspect, and terminate long-running background processes.<\/p>\n<div>\n<figure>\n<pre data-language=\"ts\"><code class=\"language-ts\"><div><div><span>const<\/span><span> <\/span><span>process<\/span><span> <\/span><span>=<\/span><span> <\/span><span>await<\/span><span> <\/span><span>sandbox<\/span><span>.<\/span><span>startProcess<\/span><span>(<\/span><span>\"node server.js\"<\/span><span>)<\/span><span>;<\/span><\/div><\/div><div><div><span>console<\/span><span>.<\/span><span>log<\/span><span>(<\/span><span>`Started process <\/span><span>${<\/span><span>process<\/span><span>.<\/span><span>id<\/span><span>}<\/span><span> with PID <\/span><span>${<\/span><span>process<\/span><span>.<\/span><span>pid<\/span><span>}<\/span><span>`<\/span><span>)<\/span><span>;<\/span><\/div><\/div><div><div>\n<\/div><\/div><div><div><span>\/\/ Monitor the process<\/span><\/div><\/div><div><div><span>const<\/span><span> <\/span><span>logStream<\/span><span> <\/span><span>=<\/span><span> <\/span><span>await<\/span><span> <\/span><span>sandbox<\/span><span>.<\/span><span>streamProcessLogs<\/span><span>(<\/span><span>process<\/span><span>.<\/span><span>id<\/span><span>)<\/span><span>;<\/span><\/div><\/div><div><div><span>for<\/span><span> <\/span><span>await<\/span><span> (<\/span><span>const<\/span><span> <\/span><span>log<\/span><span> <\/span><span>of<\/span><span> <\/span><span>parseSSEStream<\/span><span>&lt;<\/span><span>LogEvent<\/span><span>&gt;<\/span><span>(<\/span><span>logStream<\/span><span>)) <\/span><span>{<\/span><\/div><\/div><div><div><span><span>  <\/span><\/span><span>console<\/span><span>.<\/span><span>log<\/span><span>(<\/span><span>`Server: <\/span><span>${<\/span><span>log<\/span><span>.<\/span><span>data<\/span><span>}<\/span><span>`<\/span><span>)<\/span><span>;<\/span><\/div><\/div><div><div><span>}<\/span><\/div><\/div><\/code><\/pre>\n<div><\/div>\n<\/figure>\n<\/div>\n<ul>\n<li>listProcesses() &#8211; List all running processes<\/li>\n<li>getProcess(id) &#8211; Get detailed process status<\/li>\n<li>killProcess(id, signal) &#8211; Terminate specific processes<\/li>\n<li>killAllProcesses() &#8211; Kill all processes<\/li>\n<li>streamProcessLogs(id, options) &#8211; Stream logs from running processes<\/li>\n<li>getProcessLogs(id) &#8211; Get accumulated process output<\/li>\n<\/ul>\n<h4>Git integration<\/h4>\n<p>Clone Git repositories directly into the sandbox.<\/p>\n<div>\n<figure>\n<pre data-language=\"ts\"><code class=\"language-ts\"><div><div><span>await<\/span><span> <\/span><span>sandbox<\/span><span>.<\/span><span>gitCheckout<\/span><span>(<\/span><span>\"https:\/\/github.com\/user\/repo\"<\/span><span>,<\/span><span> <\/span><span>{<\/span><\/div><\/div><div><div><span><span>  <\/span><\/span><span>branch<\/span><span>:<\/span><span> <\/span><span>\"main\"<\/span><span>,<\/span><\/div><\/div><div><div><span><span>  <\/span><\/span><span>targetDir<\/span><span>:<\/span><span> <\/span><span>\"my-project\"<\/span><span>,<\/span><\/div><\/div><div><div><span>}<\/span><span>)<\/span><span>;<\/span><\/div><\/div><\/code><\/pre>\n<div><\/div>\n<\/figure>\n<\/div>\n<p>Sandboxes are still experimental. We&#8217;re using them to explore how isolated, container-like workloads might scale on Cloudflare \u2014 and to help define the developer experience around them.<\/p>","protected":false},"excerpt":{"rendered":"<p>We\u2019ve shipped a major release for the @cloudflare\/sandbox SDK, turning it into a full-featured, container-based execution platform that runs securely on Cloudflare Workers. This update adds live streaming of output, persistent Python and JavaScript code interpreters with rich output support (charts, tables, HTML, JSON), file system access, Git operations, full background process control, and the [&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-27","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/posts\/27","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=27"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/posts\/27\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/media?parent=27"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/categories?post=27"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.securinsight.ca\/index.php\/wp-json\/wp\/v2\/tags?post=27"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}