🛡️ Security

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:

The sandbox ensures that none of this is possible. Verification code runs in a completely isolated environment with strict resource limits.

🔐 Defence in Depth

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

📝
AI Code
Verification JavaScript from the LLM
🔍
Static Analysis
Check for forbidden patterns
Isolated VM
Strict context, timeout, memory cap
📤
Result
Boolean + execution metadata

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

✅ Allowed Inside Sandbox
  • 🔢 Math operations (arithmetic, trig, etc.)
  • 🔤 String manipulation (split, join, regex)
  • 📋 Array & Object operations
  • 🔁 Loops and conditionals
  • 📐 JSON parse/stringify
  • ⏱️ Date operations
  • 🧮 Pure function definitions
🚫 Blocked Inside Sandbox
  • 📁 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:

ResourceDescriptionLimit
⏱️ Execution TimeMaximum time before the script is killed5,000ms
💾 MemoryMaximum heap allocation32MB
📏 Code SizeMaximum source code length10KB
🔄 Stack DepthMaximum recursion depth100 frames
📊 Output SizeMaximum return value size1KB
// The CodeSandbox implementation class CodeSandbox { execute(code, timeoutMs = 5000) { // 1. Static analysis — reject dangerous patterns if (this.hasForbiddenPatterns(code)) { return { passed: false, error: 'Forbidden code pattern' }; } // 2. Create isolated context (no globals) const context = { Math, JSON, parseInt, parseFloat, String, Number, Array, Object, Boolean, Date, RegExp, Map, Set, isNaN, isFinite, // That's it — nothing else! }; // 3. Execute with timeout try { const script = new vm.Script(code, { timeout: timeoutMs }); const result = script.runInNewContext(context); return { passed: result === true, output: result }; } catch (e) { return { passed: false, error: e.message }; } } }

Timeout & Error Handling

The sandbox handles several failure modes gracefully:

// Forbidden pattern detection const FORBIDDEN = [ /\brequire\s*\(/, // Node.js imports /\bimport\s+/, // ES module imports /\bfetch\s*\(/, // Network requests /\beval\s*\(/, // Dynamic code execution /\bFunction\s*\(/, // Function constructor /\bprocess\b/, // Node.js process object /\bglobal\b/, // Global scope access /\b__dirname\b/, // File path access /\bchild_process\b/, // Process spawning /\bsetTimeout\b/, // Async timing /\bsetInterval\b/, // Repeated execution ];
⚡ Performance Note

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