Skip to content

Code Runner

Execute Python and JavaScript code instantly in secure WebAssembly sandboxes with millisecond response times.

Overview

Code Runner is a built-in capability that provides AI agents with instant code execution through WebAssembly isolation. When enabled on your MCP Gateway, agents can run Python and JavaScript code in fresh sandboxes with complete memory isolation, delivering both security and performance.

Key Features

  • Instant Execution: Under 10ms instantiation overhead
  • Complete Isolation: Fresh WASM instance for every request
  • Standard Libraries: Python standard library and modern JavaScript (ES6+) included
  • Memory Safety: 128MB isolated memory per execution
  • No State Persistence: Clean environment every run

How to Enable

  1. Navigate to your MCP Gateway settings
  2. Locate Code Runner in the Built-in Capabilities section
  3. Toggle the capability ON
  4. Save your configuration

Once enabled, any AI agent connected to your gateway can execute code through the MCP protocol.

Supported Languages

Python

  • Version: Python 3.11
  • Libraries: Core standard library modules (json, math, datetime, re, etc.)
  • Memory: 128MB heap
  • CPU Time: Max 100ms
  • Execution Time: 30 second timeout

JavaScript

  • Version: Modern ES6+
  • Runtime: QuickJS in WASM
  • Features: Arrow functions, async/await, destructuring, spread operators, template literals
  • Libraries: Core standard library (no DOM/Browser APIs)
  • Memory: 128MB heap
  • CPU Time: Max 100ms
  • Execution Time: 30 second timeout

What AI Agents Can Do

Data Transformations

  • Parse and transform JSON data structures
  • Convert between different data formats
  • Aggregate and summarize information
  • Clean and normalize data

Mathematical Calculations

  • Perform statistical analysis
  • Calculate compound interest and financial metrics
  • Run scientific computations
  • Generate mathematical models

String Processing

  • Analyze text content
  • Extract patterns using regular expressions
  • Transform and format text
  • Generate reports from templates

Algorithm Implementation

  • Sort and filter data
  • Implement custom business logic
  • Create data validation rules
  • Generate dynamic content

Capability Behavior

Performance Characteristics

MetricValueNotes
Instantiation<10msSandbox creation overhead
Memory Limit128MBPer execution
CPU TimeMax 100msMaximum CPU time
Timeout30 secondsMaximum execution time
Code Size10KBMaximum code length
Output Limit1MBMaximum output size
ConcurrencyUnlimitedEach in isolated sandbox

Automatic Features

  • Fresh sandbox for every execution
  • Automatic memory cleanup
  • Resource limit enforcement
  • Error isolation and handling

Security Enforcement

  • Complete memory isolation between executions
  • No access to host system
  • No network capabilities
  • No file system access
  • Resource limits strictly enforced

Limitations

No External Libraries

Code Runner includes only standard libraries. For packages like numpy, pandas, requests, or machine learning frameworks, use Virtual Machine instead.

No File System

  • No file read/write operations
  • No persistent storage
  • Use Files capability for file operations

No Network Access

  • No HTTP requests
  • No database connections
  • Use HTTP Client capability for API calls

No State Persistence

  • Each execution starts fresh
  • No global variables persist
  • No session management

When to Use Code Runner vs Virtual Machine

Use Code Runner for:

  • Quick calculations (< 1 second)
  • Data transformations
  • String processing
  • Template rendering
  • JSON manipulation
  • Standard library operations

Use Virtual Machine for:

  • Data science with pandas/numpy
  • Machine learning workflows
  • Web scraping
  • File processing
  • Long-running computations
  • External package dependencies

Typical Applications

Financial Calculations

AI agents use Code Runner to perform quick financial calculations like compound interest, loan amortization, or currency conversions using standard mathematical operations.

Data Format Conversion

Agents transform data between formats such as CSV to JSON, restructure nested objects, or aggregate data from multiple sources into unified formats.

Text Analysis

Agents analyze text for patterns, extract information using regular expressions, calculate statistics about content, or generate formatted reports.

Business Logic Implementation

Agents implement custom validation rules, calculate business metrics, or apply complex conditional logic to data processing tasks.

Pricing

Code Runner is included with standard MCP Gateway usage:

  • No per-execution charges
  • No time-based billing
  • Counts as single gateway request

Next Steps

Platform Features