Secure Sandbox Execution
AI-generated verification code runs in a locked-down JavaScript VM — no file access, no network, no escape.
Why Sandboxing Is Critical
Turbo's verification system requires executing AI-generated code. This is inherently dangerous — the AI might generate code that:
- Reads sensitive files from the server
- Makes network requests to exfiltrate data
- Spawns processes or runs system commands
- Enters infinite loops, consuming all CPU
- Allocates unbounded memory, crashing the server
The sandbox ensures that none of this is possible. Verification code runs in a completely isolated environment with strict resource limits.
The sandbox implements multiple layers of protection: code analysis before execution, a restricted VM context, resource limits, and timeout enforcement. Even if one layer is bypassed, the others still contain the threat.
Sandbox Architecture
The red dashed lines represent the security boundary. Code enters the sandbox through a narrow, controlled interface and only a simple result exits. No references to the host environment leak through.
Allowed vs Blocked
- 🔢 Math operations (arithmetic, trig, etc.)
- 🔤 String manipulation (split, join, regex)
- 📋 Array & Object operations
- 🔁 Loops and conditionals
- 📐 JSON parse/stringify
- ⏱️ Date operations
- 🧮 Pure function definitions
- 📁 File system access (fs, path)
- 🌐 Network requests (fetch, http, net)
- ⚙️ Process spawning (child_process)
- 📦 Module imports (require, import)
- 🔧 eval() and Function() constructor
- 🖥️ Global objects (process, global)
- ⏰ setTimeout / setInterval
Resource Constraints
Every sandbox execution is constrained by hard limits to prevent resource abuse:
| Resource | Description | Limit |
|---|---|---|
| ⏱️ Execution Time | Maximum time before the script is killed | 5,000ms |
| 💾 Memory | Maximum heap allocation | 32MB |
| 📏 Code Size | Maximum source code length | 10KB |
| 🔄 Stack Depth | Maximum recursion depth | 100 frames |
| 📊 Output Size | Maximum return value size | 1KB |
Timeout & Error Handling
The sandbox handles several failure modes gracefully:
- Timeout: Scripts exceeding 5 seconds are killed immediately. The candidate is marked as failed with
TIMEOUTstatus - Runtime Error: Exceptions (TypeError, ReferenceError, etc.) cause a fail — the error message is captured for debugging
- Non-boolean Return: If the code returns something other than
true, it's treated as a failure — there's no ambiguity - Static Analysis Rejection: Code containing forbidden patterns (require, import, fetch, eval) is rejected before execution
Most verification code executes in under 10ms. The 5-second timeout is generous — if code takes that long, it's almost certainly stuck in an infinite loop or inefficient recursion. Fast execution is itself a signal of good verification code.
See safe verification in action
⚡ Try Turbo in Synapse