Skip to main content

Overview

The Code Execution API lets you run code in any supported language with a single API call. Code runs in fully isolated sandboxes with per-execution process, filesystem, and resource isolation.
  • 11 languages — Python, JavaScript, TypeScript, Bash, C, C++, Go, Ruby, Rust, Java, C#
  • Millisecond overhead — sandboxes are created in ~5ms, no VM boot needed
  • Session persistence — reuse sandboxes across requests, files persist between executions
  • Secure — each execution runs in its own isolated environment with resource limits
  • Simple API — just send language and code, get stdout back

Supported Languages

LanguageVersionCompiledTypical Execution Time
Python3.12No~30ms
JavaScriptNode 22No~85ms
TypeScriptNode 22No~90ms
Bash5.2No~3ms
Cgcc 13Yes~1ms (after compile)
C++g++ 13Yes~3ms (after compile)
Go1.22Yes~500ms (compile heavy)
Ruby3.2No~50ms
RuststableYes~1s (compile heavy)
JavaOpenJDK 21Yes~500ms (JVM startup)
C#.NET 10No~800ms (warm)

API

Execute Code

POST /v1/execute
Authorization: Bearer rt_live_xxx
Content-Type: application/json
Request body:
{
  "language": "python",
  "code": "print(sum(range(1, 101)))"
}
Or with multi-file support and sessions:
{
  "language": "python",
  "session_id": "abc-123-def",
  "files": [
    { "name": "main.py", "content": "from utils import add\nprint(add(1, 2))" },
    { "name": "utils.py", "content": "def add(a, b): return a + b" }
  ],
  "stdin": "optional input",
  "run_timeout": 300000
}
FieldTypeRequiredDescription
languagestringYesLanguage identifier (see table above)
codestringYes*Code to execute (shorthand for single file)
filesarrayYes*Array of { name, content } for multi-file support
stdinstringNoStandard input to pass to the program
session_idstringNoReuse a persistent sandbox (files persist between requests)
versionstringNoVersion selector (default: * = latest)
run_timeoutnumberNoRun timeout in ms (default: 300000 = 5 minutes)
compile_timeoutnumberNoCompile timeout in ms (default: 60000 = 1 minute)
*Either code or files must be provided.

Response

{
  "language": "python",
  "version": "3.12.3",
  "session_id": "a1b2c3d4-e5f6-...",
  "run": {
    "stdout": "5050\n",
    "stderr": "",
    "code": 0,
    "signal": null,
    "time_ms": 22,
    "memory_kb": 9088
  }
}
The response always includes session_id. Pass it back in subsequent requests to reuse the same sandbox — files, env vars, and installed packages persist within the session. For compiled languages, the response includes a compile field:
{
  "language": "c",
  "version": "13.3.0",
  "session_id": "...",
  "compile": {
    "stdout": "",
    "stderr": "OK (0.085 sec real)",
    "code": 0,
    "time_ms": 85,
    "memory_kb": 12288
  },
  "run": {
    "stdout": "Hello from C!\n",
    "stderr": "",
    "code": 0,
    "signal": null,
    "time_ms": 1,
    "memory_kb": 1152
  }
}

Sessions

Sessions let you maintain state across multiple execution requests:
# Request 1: Write a file
curl -X POST /v1/execute -d '{
  "language": "python",
  "code": "open(\"data.txt\", \"w\").write(\"hello\")"
}'
# Response includes session_id: "abc-123"

# Request 2: Read the file (reusing session)
curl -X POST /v1/execute -d '{
  "language": "python",
  "session_id": "abc-123",
  "code": "print(open(\"data.txt\").read())"
}'
# stdout: "hello"
Sessions are automatically cleaned up after 10 minutes of inactivity.

List Runtimes

GET /v1/execute/runtimes
Returns the list of installed language runtimes with versions and aliases.

SDK

import { RunTools } from '@runtools/sdk';

const rt = new RunTools({ apiKey: 'rt_live_xxx' });

// Simple execution
const result = await rt.execute({
  language: 'python',
  code: 'print("Hello from RunTools!")',
});
console.log(result.run.stdout); // "Hello from RunTools!\n"

// With session persistence
const r1 = await rt.execute({
  language: 'python',
  code: 'open("data.txt", "w").write("hello")',
});

const r2 = await rt.execute({
  language: 'python',
  sessionId: r1.session_id,
  code: 'print(open("data.txt").read())',
});
console.log(r2.run.stdout); // "hello"

// List available runtimes
const runtimes = await rt.runtimes();
console.log(runtimes);

CLI

# Execute inline code
runtools execute --lang python --code 'print(42)'

# Execute from file
runtools execute --lang python --file script.py

# With session persistence
runtools execute --lang python --code 'x = 42' --session abc-123

# With stdin
runtools execute --lang python --code 'print(input())' --stdin 'hello'

# JSON output (for scripting)
runtools execute --lang python --code 'print(42)' --json

# Quiet mode (stdout only, for piping)
runtools execute --lang python --code 'print(42)' --quiet | head -1

# List available runtimes
runtools execute runtimes

Examples

import math
print(f"Pi = {math.pi:.10f}")
primes = [n for n in range(2, 50) if all(n % i != 0 for i in range(2, n))]
print(f"Primes under 50: {primes}")

Security

Each execution runs in a fully isolated sandbox with:
  • Process isolation — separate process namespace, cannot see other processes
  • Filesystem isolation — minimal filesystem, read-only system directories
  • Resource limits — CPU time, wall time, memory, file size, and process count limits
  • Network disabled — no outbound connections from executed code
  • Unprivileged execution — code runs without elevated privileges
  • Session isolation — each session has its own filesystem; sessions are cleaned up after 10 minutes of inactivity

Architecture

Code execution runs on dedicated infrastructure separate from sandbox VMs:
  • Requests are authenticated and routed to the best available execution node
  • Each node runs multiple isolated sandboxes in parallel
  • Horizontal scaling — add more nodes, they are auto-discovered
  • Sessions persist across requests within a node; cleaned up after idle timeout

Use Cases

AI Agent Code Execution

Run code generated by AI agents to verify correctness, process data, or interact with APIs

Code Evaluation

Evaluate user-submitted code safely in isolated sandboxes for assessments or competitions

Data Processing

Run Python/R scripts for data transformation, analysis, or report generation

Education

Interactive coding environments for tutorials, courses, and coding challenges