> ## Documentation Index
> Fetch the complete documentation index at: https://noorle.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Code Runner

> Execute Python and JavaScript code instantly. Sandboxed, secure environment for instant computations.

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

```python theme={null}
# 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

```javascript theme={null}
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

```python theme={null}
import json

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

Output:

```
Alice
```

## Input/Output

### Pass Data to Code

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

### Return Structured Data

```python theme={null}
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

| Limit       | Value      | Notes                                    |
| ----------- | ---------- | ---------------------------------------- |
| Timeout     | 30 seconds | Maximum execution time                   |
| Memory      | 128MB      | Per execution (configurable up to 512MB) |
| CPU Time    | \~100ms    | Maximum CPU time                         |
| Code Size   | 10KB       | Maximum code length                      |
| Output Size | 1MB        | Console output limit                     |
| Network     | Disabled   | No HTTP requests allowed                 |
| File I/O    | Disabled   | No 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](https://noorle.com/pricing/).

Monitor in **Account** > **Usage** dashboard.

## Common Recipes

### Format Data

```python theme={null}
data = "hello,world,test"
items = data.split(",")
formatted = [item.upper() for item in items]
print(",".join(formatted))
```

### Calculate Statistics

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

### Transform JSON

```python theme={null}
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 Case            | Capability    |
| ------------------- | ------------- |
| Quick calculations  | Code Runner ✓ |
| Data transformation | Code Runner ✓ |
| JSON parsing        | Code Runner ✓ |
| Heavy computation   | Sandbox       |
| External packages   | Sandbox       |
| File operations     | Files         |
| Web requests        | HTTP Client   |

## Next Steps

* [Sandbox - Full Compute](/use/capabilities/sandbox)
* [Files - Persistent Storage](/use/capabilities/files)
* [HTTP Client - API Access](/use/capabilities/http-client)
