sandbox-sdk

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

3|Updated Nov 8, 2014
One-click install
npx skills add https://github.com/mintuz/.dotfiles --skill sandbox-sdk-mintuz
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sandbox-sdk
Source: https://github.com/mintuz/.dotfiles/tree/main/agents/.agents/skills/sandbox-sdk
Command: npx skills add https://github.com/mintuz/.dotfiles --skill sandbox-sdk-mintuz

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Executing untrusted or LLM-generated code safely requires isolated environments, and setting up secure sandboxes with command execution, file operations, and code interpretation on Cloudflare Workers involves complex configuration that this Skill streamlines. ## Core Features & Use Cases - Sandboxed Command Execution: Run shell commands and scripts in isolated containers with stdout, stderr, and exit code capture via exec(). - Code Interpreter for AI: Execute LLM-generated Python, JavaScript, or TypeScript code with rich outputs and persistent state using runCode() and code contexts. - File and Port Management: Write, read, and list files in the sandbox, and expose HTTP services through preview URLs with exposePort(). - Use Case: Build an AI coding assistant that executes user-submitted Python data analysis scripts in isolated Cloudflare Workers containers, returning charts and results without risking your infrastructure. ## Quick Start Ask the AI to set up a Cloudflare Worker using the Sandbox SDK that runs Python code in an isolated sandbox and returns the execution results.

Frequently Asked Questions about sandbox-sdk

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

FAQPage Schema
How do I run untrusted code securely on Cloudflare Workers?

Use the @cloudflare/sandbox SDK to get an isolated sandbox via getSandbox(env.Sandbox, sandboxId), then execute code with sandbox.exec() for shell commands or sandbox.runCode() for interpreted code. Each sandbox runs in its own container with configurable sleep and destroy lifecycle.

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

exec() runs shell commands and returns stdout, stderr, and exit codes, suiting scripts and build pipelines. runCode() executes Python, JavaScript, or TypeScript with rich outputs like charts and tables, plus state persistence across calls via code contexts, making it better for LLM-generated code.

Does the Cloudflare Sandbox SDK support preview URLs for exposed ports?

Yes, sandbox.exposePort(8080) returns a preview URL for HTTP services running in the sandbox. In production, preview URLs require a custom domain with wildcard DNS because the .workers.dev domain does not support preview URL subdomains.

Why does my Cloudflare Sandbox Worker fail to deploy?

Deployment fails if the Worker entry does not re-export the Sandbox class with export { Sandbox } from '@cloudflare/sandbox'. Also verify wrangler.jsonc includes the containers, durable_objects bindings, and migrations configuration exactly as required.

How do I add Python or Node packages to a Cloudflare sandbox?

Extend the base Dockerfile from docker.io/cloudflare/sandbox:0.7.0 with RUN pip install or npm install -g commands for your dependencies. Keep images lean since image size affects container cold start time.

When should I not use the Cloudflare Sandbox SDK?

Avoid it if you cannot use Docker for local development, since docker info must succeed. Also avoid hardcoding sandbox IDs for multi-user applications; instead derive IDs from user or session identifiers and call destroy() to free temporary sandboxes.