sandbox-sdk

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

Updated Nov 23, 2024
One-click install
npx skills add https://github.com/tokisakiyuu/dotfiles --skill sandbox-sdk-tokisakiyuu
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: sandbox-sdk
Source: https://github.com/tokisakiyuu/dotfiles/tree/main/home/dot_claude/skills/sandbox-sdk
Command: npx skills add https://github.com/tokisakiyuu/dotfiles --skill sandbox-sdk-tokisakiyuu

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 wiring up containers, Durable Objects, and code interpreters on Cloudflare Workers involves many configuration details that are easy to get wrong. ## 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(), rich outputs, and persistent state across calls. - File and Port Management: Read, write, and list files in the sandbox, and expose HTTP services through preview URLs. - Use Case: Build an AI coding assistant that writes Python to /workspace, executes it in a per-user sandbox, returns charts and results, and destroys the container when the session ends. ## Quick Start Ask the assistant to create a Cloudflare Worker that uses the Sandbox SDK to run Python code in an isolated sandbox and return the 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 Worker?▼

Use the @cloudflare/sandbox SDK's runCode() method, which executes Python, JavaScript, or TypeScript in an isolated container and returns rich outputs like text, HTML, and images. Create a code context with createCodeContext() to persist state across executions.

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() is a code interpreter for LLM-generated code, returning rich outputs and supporting state persistence within a context.

Does the Cloudflare Sandbox SDK require Docker?▼

Yes, Docker is required for local development, and docker info must succeed before running the sandbox locally. In production on Cloudflare Workers, containers are managed by the platform.

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

The Worker entry 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 the export is a common cause of deployment failure.

Can I expose an HTTP server running inside a sandbox?▼

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

How long do Cloudflare sandbox containers stay alive?▼

Containers sleep after 10 minutes of inactivity by default, configurable via the sleepAfter option or prevented with keepAlive. Call destroy() to immediately terminate a sandbox and free its resources.