sandbox-sdk

Build sandboxed code execution environments on Cloudflare Workers using the Sandbox SDK.

Updated Aug 2, 2026
One-click install
npx skills add https://github.com/leonardoacosta/agents --skill sandbox-sdk-leonardoacosta
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sandbox-sdk
Source: https://github.com/leonardoacosta/agents/tree/main/skills/sandbox-sdk
Command: npx skills add https://github.com/leonardoacosta/agents --skill sandbox-sdk-leonardoacosta

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @cloudflare/sandbox, and includes references (resource) components.

What problem does it solve? Running untrusted or LLM-generated code safely requires isolated execution environments, and configuring Cloudflare's Sandbox SDK involves precise wrangler configuration, Durable Object bindings, and lifecycle management that are easy to get wrong. ## Core Features & Use Cases - Command and Code Execution: Run shell commands with exec() or execute Python, JavaScript, and TypeScript with runCode() for rich outputs and persistent interpreter state. - File and Port Management: Write, read, and list files inside sandboxes, and expose HTTP services through preview URLs. - Use Case: Build an AI code interpreter where an agent generates Python data-analysis code, executes it in an isolated per-session sandbox with pandas, and returns charts and results to the user. ## Quick Start Ask the agent to set up a Cloudflare Worker with the Sandbox SDK that runs Python code in an isolated sandbox and returns the execution result.

Frequently Asked Questions about sandbox-sdk

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I run LLM-generated code in a Cloudflare sandbox?

Use sandbox.runCode() with a code context created via sandbox.createCodeContext(). It supports Python, JavaScript, and TypeScript, persists state within the context, and returns rich outputs like text, HTML, and images.

What is the difference between exec() and runCode() in the Sandbox SDK?

exec() runs shell commands and returns stdout, stderr, and exit codes, suiting scripts and build pipelines. runCode() executes code in a managed interpreter with state persistence and rich outputs, making it better for LLM-generated code and data analysis.

Does the Cloudflare Sandbox SDK require Docker?

Yes, Docker is required for local development and docker info must succeed before running the sandbox locally. The base image cloudflare/sandbox includes Python 3.11, Node.js 20, and common tools, and you can extend the Dockerfile with extra packages.

Why won't my Cloudflare Worker deploy with the Sandbox SDK?

The Worker must re-export the Sandbox class with export { Sandbox } from '@cloudflare/sandbox', and wrangler.jsonc must include the containers, durable_objects bindings, and a migration with new_sqlite_classes. Missing any of these blocks deployment.

Can I expose HTTP services running inside a sandbox?

Yes, call sandbox.exposePort(8080) to get a preview URL for the service. In production, preview URLs require a custom domain with wildcard DNS because the default .workers.dev domain does not support preview URL subdomains.