sandbox-sdk

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

Updated Dec 9, 2025
One-click install
npx skills add https://github.com/Aki2022/skills --skill sandbox-sdk-aki2022
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: sandbox-sdk
Source: https://github.com/Aki2022/skills/tree/main/sandbox-sdk
Command: npx skills add https://github.com/Aki2022/skills --skill sandbox-sdk-aki2022

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 containers, Durable Objects, and code interpreters on Cloudflare Workers involves many error-prone setup steps. ## 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. - File and Port Management: Write, read, and list files in the sandbox, and expose HTTP services via preview URLs. - Use Case: Build an AI coding assistant that executes user-submitted Python scripts in isolated per-session sandboxes, returns results with charts, and destroys the container when the session ends. ## Quick Start Ask the AI to set up a Cloudflare Worker using @cloudflare/sandbox that runs a Python snippet in a sandbox and returns the output.

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 createCodeContext(). It supports Python, JavaScript, and TypeScript, returns rich outputs like text and images, and persists state within the context across calls.

How do I execute shell commands in a Cloudflare Worker sandbox?▼

Call sandbox.exec() with your command string after getting a sandbox via getSandbox(env.Sandbox, id). The result includes stdout, stderr, exitCode, and a success flag, with options for cwd, env vars, timeout, and stdin.

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

exec() runs shell commands directly and suits scripts and build pipelines needing exit codes. runCode() is a code interpreter for LLM-generated code, offering rich outputs, error objects, and state persistence across executions.

Why won't my Cloudflare sandbox Worker deploy?▼

The Worker must 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.

Do preview URLs work on workers.dev domains?▼

No, preview URLs from exposePort() require a custom domain with wildcard DNS such as *.yourdomain.com. The default .workers.dev domain does not support the subdomains needed for preview URLs.

How long do Cloudflare sandbox containers stay alive?▼

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