Skip to main content
Code Runner executes Python and JavaScript code in a sandboxed environment. Perfect for calculations, data transformation, and quick automation.

Key Features

  • Python 3.11+ - Full Python stdlib
  • JavaScript/Node.js - Modern ES6+ support
  • Sandboxed - Isolated from system and other sessions
  • 30-second timeout - Prevents runaway code
  • No Network Access - Isolated from external services
  • Input/Output Handling - Pass data to code and capture results
  • No Dependencies - Core libraries only (upgrade to Sandbox for pip/npm)

How to Enable

For Agents

  1. Agents > Select Agent > Settings > Capabilities
  2. Attach Code Runner

For MCP Gateways

  1. Gateways > Select Gateway > Capabilities
  2. Attach Code Runner

Usage Examples

Python Calculation

# Calculate factorial
def factorial(n):
    return 1 if n <= 1 else n * factorial(n - 1)

result = factorial(5)
print(f"5! = {result}")
Output:
5! = 120

JavaScript Data Processing

const data = [1, 2, 3, 4, 5];
const sum = data.reduce((a, b) => a + b, 0);
const average = sum / data.length;
console.log(`Average: ${average}`);
Output:
Average: 3

JSON Parsing

import json

data = '{"name": "Alice", "age": 30}'
parsed = json.loads(data)
print(parsed['name'])
Output:
Alice

Input/Output

Pass Data to Code

# Receive input from agent
input_data = {"numbers": [1, 2, 3, 4, 5]}
total = sum(input_data["numbers"])
print(total)

Return Structured Data

result = {
    "status": "success",
    "total": 15,
    "average": 3.0
}
print(result)

Available Libraries

Python Standard Library

  • json, csv, re, datetime, math, statistics
  • collections, itertools, functools
  • hashlib, urllib, base64
  • logging, pprint, sys, os (limited)

JavaScript Standard Library

  • All ES6+ features
  • JSON, Math, Date, RegExp
  • Array methods, String methods
  • No external npm packages

Resource Limits

LimitValueNotes
Timeout30 secondsMaximum execution time
Memory128MBPer execution (configurable up to 512MB)
CPU Time~100msMaximum CPU time
Code Size10KBMaximum code length
Output Size1MBConsole output limit
NetworkDisabledNo HTTP requests allowed
File I/ODisabledNo file read/write

Limitations

  • No network access
  • No file I/O (use Files capability instead)
  • No package installation (use Sandbox for pip/npm)
  • No background processes
  • No system calls

Cost

For current pricing details, see Pricing. Monitor in Account > Usage dashboard.

Common Recipes

Format Data

data = "hello,world,test"
items = data.split(",")
formatted = [item.upper() for item in items]
print(",".join(formatted))

Calculate Statistics

import statistics
values = [10, 20, 30, 40, 50]
print(f"Mean: {statistics.mean(values)}")
print(f"Median: {statistics.median(values)}")

Transform JSON

import json
input_json = '{"a": 1, "b": 2}'
data = json.loads(input_json)
output = {k: v * 2 for k, v in data.items()}
print(json.dumps(output))

Troubleshooting

Timeout Error

Code ran longer than 30 seconds. Optimize for speed or use Sandbox for heavy computation.

Memory Error

Exceeded 128MB memory limit. Reduce data size or process in chunks.

Module Not Found

Only stdlib available. For third-party packages, use Sandbox instead.

No Output Captured

Ensure you print() or return results. Code without output shows success but no data.

When to Use

Use CaseCapability
Quick calculationsCode Runner ✓
Data transformationCode Runner ✓
JSON parsingCode Runner ✓
Heavy computationSandbox
External packagesSandbox
File operationsFiles
Web requestsHTTP Client

Next Steps