Cloud Development · 6 min

E2B + Claude Code Sandbox: Secure Cloud Development Environment Guide

Complete guide to run Claude Code in isolated E2B cloud sandbox. Install components safely, execute prompts in secure environment, and develop without local system risks.

  • 読了目安 4 分
  • 8 セクション
  • 2026年10月9日に更新
このページの内容

By Daniel Ávila and Claude Code Templates contributors. Original article.

Benefits of Secure Sandbox Execution

Running Claude Code in an isolated E2B cloud sandbox provides essential security and development advantages:

BenefitDescription
🔒 Complete IsolationCode runs in a separate cloud environment with zero access to your local system, files, or network.
🛡️ No Local ImpactEliminates risk of system modifications, file corruption, or security vulnerabilities on your machine.
🚀 Clean EnvironmentFresh Ubuntu with Claude Code pre-installed, ensuring consistent execution without dependency conflicts.
☁️ Remote ExecutionIntensive operations run in the cloud without consuming your local CPU, memory, or storage.
🧪 Safe TestingTest new agents and commands risk-free, with automatic cleanup after execution.

E2B Claude Code Sandbox Component

Claude Code Templates provides a ready-to-use E2B sandbox integration:

🔧 What's Included

ComponentDescription
E2B Launcher ScriptPython script that creates, configures, and manages E2B sandbox instances with Claude Code.
Automatic SetupDownloads dependencies, checks Python environment, and installs E2B SDK automatically.
Component IntegrationInstalls any specified agents, commands, MCPs, settings, and hooks inside the sandbox.

Prerequisites

You'll need two API keys to use the E2B sandbox:

Installation and Usage

Quick Start, Simple Execution

# Execute a prompt in secure E2B sandbox with API keys
npx claude-code-templates@latest --sandbox e2b \
  --e2b-api-key your_e2b_key \
  --anthropic-api-key your_anthropic_key \
  --prompt "Create a React todo app with TypeScript"

# Or use environment variables (set E2B_API_KEY and ANTHROPIC_API_KEY)
npx claude-code-templates@latest --sandbox e2b --prompt "Create a React todo app with TypeScript"

# Interactive mode, let the CLI guide you
npx claude-code-templates@latest --sandbox e2b \
  --e2b-api-key your_e2b_key \
  --anthropic-api-key your_anthropic_key

This command will:

  • ✓ Create secure E2B cloud sandbox
  • ✓ Execute your prompt using Claude Code
  • ✓ Download generated files to sandbox-xxxxx folder
  • ✓ Automatically cleanup after execution

Advanced Usage, With Specific Agent

# Execute with a specific agent in sandbox
npx claude-code-templates@latest --sandbox e2b \
  --e2b-api-key your_e2b_key \
  --anthropic-api-key your_anthropic_key \
  --agent development-team/frontend-developer \
  --prompt "Create a modern todo app with TypeScript and Tailwind"

Full Stack Development

# Complete full-stack app development
npx claude-code-templates@latest --sandbox e2b \
  --e2b-api-key your_e2b_key \
  --anthropic-api-key your_anthropic_key \
  --agent development-team/fullstack-developer \
  --prompt "Create a Node.js API with PostgreSQL and authentication"

Data Science and Analysis

# Data analysis with specialized agent
npx claude-code-templates@latest --sandbox e2b \
  --e2b-api-key your_e2b_key \
  --anthropic-api-key your_anthropic_key \
  --agent ai-ml-specialists/data-scientist \
  --prompt "Analyze this dataset and create interactive visualizations"

API Key Configuration

You can provide your E2B and Anthropic API keys in two convenient ways:

🔑 Option 1: CLI Parameters (Recommended)

# Pass API keys directly as command parameters
npx claude-code-templates@latest --sandbox e2b \
  --e2b-api-key your_e2b_api_key_here \
  --anthropic-api-key your_anthropic_api_key_here \
  --prompt "Your prompt here"

Benefits:

  • ✓ No need to set up environment variables
  • ✓ Works immediately without additional configuration
  • ✓ Perfect for CI/CD pipelines and automation
  • ✓ No risk of accidentally committing keys to repositories

🌍 Option 2: Environment Variables

# Set environment variables in your shell
export E2B_API_KEY=your_e2b_api_key_here
export ANTHROPIC_API_KEY=your_anthropic_api_key_here

# Then run without API key parameters
npx claude-code-templates@latest --sandbox e2b --prompt "Your prompt here"

Note: CLI parameters take precedence over environment variables, so you can override environment settings when needed.

Environment Configuration

After first execution, the sandbox component creates these files in your project:

your-project/
├── .claude/
│   └── sandbox/
│       ├── e2b-launcher.py      # Python launcher script
│       ├── requirements.txt     # E2B SDK dependencies
│       └── .env.example         # Environment variables template
└── sandbox-xxxxxxxx/            # Generated project files (after execution)
    ├── index.html               # Your generated files
    ├── src/                     # Project source code
    └── ...

Use Cases, When You Need Sandbox Isolation

🔥 System-Level Operations

# Modify system configurations without risk
npx claude-code-templates@latest --sandbox e2b \
  --e2b-api-key your_e2b_key \
  --anthropic-api-key your_anthropic_key \
  --agent devops-cloud/system-administrator \
  --prompt "Set up nginx with multiple virtual hosts, SSL certificates, and firewall rules"

🧪 Experimental Package Installation

# Test unknown dependencies and packages safely
npx claude-code-templates@latest --sandbox e2b \
  --e2b-api-key your_e2b_key \
  --anthropic-api-key your_anthropic_key \
  --agent development-team/fullstack-developer \
  --prompt "Install and configure a complex tech stack with Redis, RabbitMQ, Elasticsearch, and their dependencies"

🛡️ Security Vulnerability Testing

# Run penetration testing tools without affecting your system
npx claude-code-templates@latest --sandbox e2b \
  --e2b-api-key your_e2b_key \
  --anthropic-api-key your_anthropic_key \
  --agent security-testing/penetration-tester \
  --prompt "Set up and run OWASP ZAP, Metasploit, and Nmap to test this application"

💣 Database Operations

# Perform destructive database migrations and schema changes
npx claude-code-templates@latest --sandbox e2b \
  --e2b-api-key your_e2b_key \
  --anthropic-api-key your_anthropic_key \
  --agent data-analytics/database-administrator \
  --prompt "Create a PostgreSQL database, run complex migrations, drop tables, and test backup/restore procedures"

Troubleshooting

Common Issues and Solutions

IssueSolution
Python Not FoundInstall Python 3.11+ from python.org/downloads
API Keys Not SetCreate .env file in .claude/sandbox/ with your E2B and Anthropic API keys
Dependencies FailedRun pip3 install -r .claude/sandbox/requirements.txt manually
Sandbox TimeoutLarge prompts may take time; configured with 15-minute timeout for complex operations

Explore 800+ Claude Code Components

Discover agents, commands, MCPs, settings, hooks, skills and templates for your Claude Code workflow

すでに作った人たちと、一緒に作ろう。

無料コミュニティに参加しましょう。毎週のライブ通話、最初に見るコース、あなたの言語のビルダーがいます。

Skoolに無料で参加