Code Execution MCP
Implements the patterns from Anthropic's "Code Execution with MCP" article for efficient AI agent operations.
Core Insight
Instead of loading thousands of tool definitions upfront and passing intermediate results through model context, agents write code that:
Discovers tools on-demand (progressive disclosure)
Processes data in a sandbox (not in context)
Returns only summarized/filtered results
Result: Up to 98.7% token reduction compared to direct tool invocation.
Features
1. Sandboxed Code Execution
Resource limits (30s timeout, 500MB memory)
Restricted builtins (safe subset)
Safe modules (json, re, math, datetime, etc.)
Workspace file utilities
2. Progressive Tool Discovery
Search tools by query without loading definitions
Get summaries first, full definitions on-demand
Organized by category (security, memory, cluster, etc.)
3. PII Tokenization
Auto-detect sensitive data (emails, phones, SSNs, etc.)
Replace with tokens before data reaches model
Restore when needed for tool calls
4. Skills Persistence
Save reusable code snippets
Build compound capabilities over time
Share across sessions
Tools
Tool | Description |
| Run Python in secure sandbox |
| Progressive tool discovery |
| Load full tool details |
| Persist reusable code |
| Load saved skill |
| List all skills |
| Tokenize PII in text |
| Restore tokenized PII |
| Persist data to workspace |
| Read from workspace |
| List workspace contents |
| Environment statistics |
Usage Examples
Efficient Data Processing
Progressive Tool Discovery
Privacy-Preserving Operations
Building Skills
Installation
Configuration
Add to ~/.claude.json:
Architecture
Security Notes
Code runs with restricted builtins (no
open,exec,evalon arbitrary input)File access limited to workspace directory
Resource limits prevent runaway execution
No network access from sandbox