sandbox-sdk

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

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

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 configuring Cloudflare's Sandbox SDK involves precise wrangler.jsonc settings, Durable Object bindings, and API choices that are easy to get wrong from memory alone. ## Core Features & Use Cases - Sandboxed Command Execution: Run shell commands with exec() and capture stdout, stderr, and exit codes inside isolated containers. - Code Interpreter for AI: Execute LLM-generated Python, JavaScript, or TypeScript with runCode(), including rich outputs and persistent state across calls via code contexts. - File and Port Management: Write, read, and list files in the sandbox, and expose HTTP services through preview URLs. - Use Case: Build an AI coding assistant that runs user-submitted Python scripts in an isolated Cloudflare Sandbox, returns results with charts, and destroys the container when the session ends. ## Quick Start Ask the assistant to set up a Cloudflare Worker using 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 the runCode() method from @cloudflare/sandbox with a code context created via createCodeContext(). It supports Python, JavaScript, and TypeScript, returns rich outputs like text and charts, and preserves state across calls within the same context.

How do I execute shell commands in Cloudflare Sandbox SDK?

Call sandbox.exec('your command') after obtaining a sandbox with getSandbox(env.Sandbox, id). The result includes stdout, stderr, exitCode, and a success flag, with options for working directory, environment variables, timeout, and stdin.

What wrangler configuration does Cloudflare Sandbox SDK require?

You need a containers entry with class_name Sandbox and a Dockerfile image, a Durable Object binding named Sandbox, and a migration with new_sqlite_classes. The Worker entry must also re-export the Sandbox class or deployment fails.

Does Cloudflare Sandbox 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 subdomains.

When should I use exec() versus runCode() in the Sandbox SDK?

Use exec() for shell commands, scripts, and build pipelines where you need exit codes and stderr capture. Use runCode() for LLM-generated code and data analysis where you want rich outputs and state persistence across executions.

How long do Cloudflare sandbox containers stay alive?

Containers sleep after 10 minutes of inactivity by default, configurable via the sleepAfter option in getSandbox(). Call destroy() to immediately free resources, and reuse the same sandbox ID to return to the same instance.