sandbox-sdk

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

Updated Oct 15, 2019
One-click install
npx skills add https://github.com/kkkaoru/dotfiles --skill sandbox-sdk-kkkaoru
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sandbox-sdk
Source: https://github.com/kkkaoru/dotfiles/tree/main/.codex/skills/sandbox-sdk
Command: npx skills add https://github.com/kkkaoru/dotfiles --skill sandbox-sdk-kkkaoru

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 environments, and this Skill guides you through building secure, containerized code execution on Cloudflare Workers with the Sandbox SDK. ## Core Features & Use Cases - Command and Code Execution: Run shell commands with exec() or execute Python, JavaScript, and TypeScript with rich outputs via runCode() and persistent code contexts. - File and Port Management: Write, read, and list files inside sandboxes, and expose HTTP services through preview URLs with exposePort(). - Use Case: Build an AI code interpreter where an agent generates Python pandas code, executes it in an isolated per-session sandbox with state persistence, and returns charts and tables to the user. ## Quick Start Ask the AI 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 sandbox on Cloudflare Workers?

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

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 code in an interpreter context with state persistence and rich outputs, making it better for AI-generated code and data analysis.

Does Cloudflare Sandbox SDK support preview URLs for exposed ports?

Yes, exposePort() 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 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 entries exactly as required.

How long do Cloudflare sandboxes stay alive and how do I clean them up?

Sandboxes sleep after 10 minutes of inactivity by default, configurable via the sleepAfter option. Call destroy() to immediately terminate a sandbox and free its resources, especially for temporary per-session sandboxes.