
Cloudflare Sandbox
- 196 repo stars
- Updated July 25, 2026
- secondsky/claude-skills
Run untrusted code safely in Linux containers at the edge via the Cloudflare Sandboxes SDK for AI code interpreters.
About
The Cloudflare Sandboxes SDK runs untrusted code securely inside Linux containers at the edge. Developers use it to execute arbitrary Python or Node.js scripts, power AI code interpreters, or run git operations in an isolated environment from their Workers.
- Secure code execution in Linux containers
- Runs untrusted Python/Node.js
- AI code-interpreter use case
- Supports git operations
Cloudflare Sandbox by the numbers
- Data as of Jul 28, 2026 (Skillselion catalog sync)
/plugin marketplace add secondsky/claude-skills/plugin install cloudflare-sandbox@claude-skillsAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| repo stars | ★ 196 |
|---|---|
| Last updated | July 25, 2026 |
| Repository | secondsky/claude-skills ↗ |
What it does
Run untrusted code safely in Linux containers at the edge via the Cloudflare Sandboxes SDK for AI code interpreters.
README.md
Cloudflare Sandboxes SDK
Status: Production Ready (Open Beta) ✅ Last Updated: 2025-10-29 Production Tested: Based on official Cloudflare tutorials (Claude Code Integration, AI Code Executor)
Auto-Trigger Keywords
Claude Code automatically discovers this skill when you mention:
Primary Keywords
- cloudflare sandbox
- cloudflare sandboxes
- @cloudflare/sandbox
- sandbox SDK
- container execution
- code execution
- isolated environment
- linux container
- secure code execution
Secondary Keywords
- execute python in cloudflare
- run node.js in cloudflare
- cloudflare code interpreter
- durable objects container
- git operations cloudflare
- AI code execution
- code playground
- interactive development environment
- CI/CD cloudflare
- build pipeline cloudflare
- workspace container
- ephemeral container
- session management
- getSandbox()
- sandbox.exec()
- runCode()
- gitCheckout()
- ubuntu container cloudflare
Error-Based Keywords
- "Class 'Sandbox' not found"
- "fetch is not defined" (cloudflare sandbox)
- "Container not ready"
- "files disappear" (cloudflare)
- "session directory wrong"
- "command wrong directory"
- "sandbox cold start"
- "nodejs_compat"
- "migrations sandbox"
- "docker build container"
- "exit code ignored"
- "persistence cloudflare"
What This Skill Does
This skill provides comprehensive knowledge for building applications with Cloudflare Sandboxes SDK - a production Beta feature that enables secure, isolated code execution in full Linux containers at the edge. It combines Workers + Durable Objects + Ubuntu Containers to provide a simple TypeScript API for running Python, Node.js, shell commands, and git operations safely.
Core Capabilities
✅ Execute Code Safely - Run Python, Node.js, shell commands in VM-isolated containers
✅ Stateful Sessions - Maintain working directory and environment across commands
✅ Git Operations - Clone repositories, run diffs, manage source code programmatically
✅ Code Interpreter - Jupyter-like API for executing code with automatic result capture
✅ Background Processes - Spawn, monitor, and manage long-running processes
✅ Full Filesystem - Read/write files, manage directories in /workspace, /tmp, /home
✅ AI Agent Integration - Run Claude Code CLI, OpenAI Agents, or custom AI workflows
✅ CI/CD Pipelines - Build, test, and deploy code in isolated environments
✅ Error Prevention - Prevents 10+ documented configuration and lifecycle errors
Known Issues This Skill Prevents
| Issue | Why It Happens | Source | How Skill Fixes It |
|---|---|---|---|
| Missing nodejs_compat | SDK requires Node.js APIs not in standard Workers | Official docs | Provides complete wrangler.jsonc config |
| Class not found | Durable Objects need migrations | DO docs | Includes proper migrations setup |
| Files disappear | Containers go idle after ~10 min, state resets | Lifecycle docs | Documents persistence patterns + R2 backup |
| Wrong directory | Each exec() uses new session | Sessions docs | Shows session management patterns |
| Exit codes ignored | Not checking result.success | Shell best practices | Enforces exit code checking |
| Cold start failures | Dependencies missing after idle | Container lifecycle | Shows cold start handling |
| Docker errors (local) | Local dev needs Docker daemon | Getting started | Clarifies Docker requirement |
| Version mismatch | npm package ≠ Docker image | GitHub issues | Keeps versions in sync |
| Resource leaks | Not destroying ephemeral sandboxes | Resource management | Shows cleanup patterns |
| Command injection | Unsanitized user input to exec() | Security best practices | Provides input validation |
When to Use This Skill
✅ Use When:
- Executing Python or Node.js code securely (code playgrounds, learning platforms)
- Building AI code execution systems (LLM-generated code runners)
- Creating interactive development environments (notebooks, IDEs, REPLs)
- Implementing CI/CD build pipelines on Cloudflare
- Running git operations programmatically (clone, diff, commit automation)
- Processing files with system tools (ffmpeg, imagemagick, pandoc)
- Building chat-based coding agents (Claude Code integration, multi-step workflows)
- Creating temporary build/test environments
- Running untrusted code safely with VM isolation
- Need stateful sessions with persistent working directory
❌ Don't Use When:
- Fast API routes (<50ms) - Use regular Workers instead
- Stateless compute - Regular Workers are faster
- Need instant cold starts - Sandboxes have ~2-3 min first run
- Only using Cloudflare Workers AI - Use
cloudflare-workers-aiskill - Only using Durable Objects - Use
cloudflare-durable-objectsskill
Quick Usage Example
# 1. Install SDK
bun add @cloudflare/sandbox@latest # preferred
# or: npm install @cloudflare/sandbox@latest
# 2. Configure wrangler.jsonc (add nodejs_compat + containers)
# See SKILL.md for full config
# 3. Write Worker
import { getSandbox } from '@cloudflare/sandbox';
export { Sandbox } from '@cloudflare/sandbox';
export default {
async fetch(request, env) {
const sandbox = getSandbox(env.Sandbox, 'my-sandbox');
const result = await sandbox.exec('python3 -c "print(2 + 2)"');
return Response.json({ output: result.stdout });
}
};
# 4. Deploy
bun run deploy # preferred
# or: npm run deploy
Result: Secure Python code execution at the edge with full Ubuntu container
Full instructions: See SKILL.md
Package Versions (Verified 2025-10-29)
| Package | Version | Status |
|---|---|---|
| @cloudflare/sandbox | 0.4.12 | ✅ Latest stable |
| cloudflare/sandbox (Docker) | 0.4.12 | ✅ Latest stable |
| wrangler | 3.80.0+ | ✅ Latest stable |
| @cloudflare/workers-types | 4.20241106.0+ | ✅ Latest stable |
Dependencies
Prerequisites:
cloudflare-worker-base(recommended for understanding Workers)cloudflare-durable-objects(recommended for understanding DO routing)
Integrates With:
cloudflare-r2(optional - for file persistence)cloudflare-kv(optional - for session state)cloudflare-d1(optional - for metadata storage)cloudflare-workers-ai(optional - for AI features)claude-api(optional - for AI agents)openai-agents(optional - for OpenAI integration)
File Structure
cloudflare-sandbox/
├── SKILL.md # Complete documentation (959 lines)
├── README.md # This file (quick reference)
├── templates/
│ ├── basic-executor.ts # One-shot code execution
│ ├── chat-agent.ts # Session-based conversational
│ ├── ci-cd.ts # Build pipeline pattern
│ └── workspace.ts # Persistent user workspace
├── references/
│ ├── persistence-guide.md # Container lifecycle deep dive
│ ├── session-management.md # Session patterns & best practices
│ ├── common-errors.md # All 10 errors + solutions
│ └── naming-strategies.md # Sandbox ID strategies
└── scripts/
├── setup-sandbox-binding.sh # Interactive wrangler config
└── test-sandbox.ts # Validation script
Official Documentation
- Cloudflare Sandboxes: https://developers.cloudflare.com/sandbox/
- Architecture: https://developers.cloudflare.com/sandbox/concepts/architecture/
- Lifecycle: https://developers.cloudflare.com/sandbox/concepts/sandboxes/
- Sessions: https://developers.cloudflare.com/sandbox/concepts/sessions/
- API Reference: https://developers.cloudflare.com/sandbox/api-reference/
- Getting Started: https://developers.cloudflare.com/sandbox/get-started/
- GitHub SDK: https://github.com/cloudflare/sandbox-sdk
- Durable Objects: https://developers.cloudflare.com/durable-objects/
- Context7 Library: N/A (too new, not yet indexed)
Related Skills
- cloudflare-worker-base - Foundation for Workers development
- cloudflare-durable-objects - Understanding DO routing and state
- cloudflare-r2 - File persistence for sandboxes
- cloudflare-kv - Session state storage
- claude-api - AI integration for code generation
- openai-agents - OpenAI Agents SDK integration
Key Concepts This Skill Explains
The 3-Layer Architecture
- Layer 1 (Worker): Handles HTTP, calls sandbox API
- Layer 2 (Durable Object): Routes by ID, maintains identity
- Layer 3 (Container): Full Ubuntu Linux, executes code
Container Lifecycle (Critical!)
- Active: Files persist, processes run (~10 min after last request)
- Idle: ALL FILES DELETED, ALL PROCESSES KILLED
- Fresh Start: Next request creates new container
Session Management
- Bash shell contexts within one sandbox
- Preserve working directory across commands
- Perfect for multi-step workflows and chat agents
Naming Strategies
- Per-User:
user-${userId}- Persistent workspace - Per-Session:
session-${timestamp}- Fresh each time - Per-Task:
build-${repo}-${commit}- Idempotent, traceable
Contributing
Found an issue or have a suggestion?
- Open an issue: https://github.com/secondsky/claude-skills/issues
- See SKILL.md for detailed documentation
License
MIT License - See main repo LICENSE file
Production Tested: Based on official Cloudflare tutorials and examples Token Savings: ~79% Error Prevention: 100% (all 10 documented issues) Ready to use! See SKILL.md for complete setup.