Skip to main content

Overview

The runtools execute command runs code in sandboxed environments directly from your terminal. Supports inline code, file execution, stdin, sessions, and JSON output for scripting.

Basic Usage

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

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

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

Options

FlagDescriptionDefault
-l, --lang <language>Programming language (required)-
-c, --code <code>Inline code to execute-
-f, --file <path>File to execute-
-s, --stdin <input>Standard input-
--stdin-file <path>Read stdin from file-
--session <id>Session ID to reuse a persistent sandbox-
-t, --timeout <ms>Run timeout in milliseconds300000
-v, --version <ver>Language versionlatest
--jsonOutput as JSON-
-q, --quietOnly output stdout (no metadata)-

Sessions

Use --session to reuse a sandbox across multiple executions. The session ID is shown in the output after each execution:
# Run code (note the session ID in output)
runtools execute --lang python --code 'open("data.txt", "w").write("hello")'
# ✓ python 3.12.3 — 22ms, 9MB
# ℹ Session: a1b2c3d4-e5f6-...

# Reuse the session — files persist!
runtools execute --lang python --session a1b2c3d4-e5f6-... --code 'print(open("data.txt").read())'
# hello
# ✓ python 3.12.3 — 15ms, 9MB
Sessions are automatically cleaned up after 10 minutes of inactivity.

Language IDs

LanguageIDAliases
Pythonpythonpy, python3
JavaScriptjavascriptjs, node
TypeScripttypescriptts
Bashbashsh
Ccgcc
C++c++cpp, g++
Gogogolang
Rubyrubyrb
Rustrustrs
Javajavajdk
C#csharpcs, dotnet

Examples

Python

runtools execute --lang python --code '
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: {primes}")
'

File Execution

# Run a local Python script
runtools execute --lang python --file ./analysis.py

# Run a C program
runtools execute --lang c --file main.c

# Run with input from file
runtools execute --lang python --file solution.py --stdin-file input.txt

JSON Output (for scripting)

# Get structured output
runtools execute --lang python --code 'print(42)' --json

# Parse with jq
runtools execute --lang python --code 'print(42)' --json | jq '.run.stdout'

# Get session ID from JSON
runtools execute --lang python --code 'print(42)' --json | jq -r '.session_id'

Quiet Mode (for piping)

# Pipe output to another command
runtools execute --lang python --code 'print("hello")' --quiet | tr 'h' 'H'

# Use in a shell script
RESULT=$(runtools execute --lang python --code 'print(2+2)' --quiet)
echo "Python says: $RESULT"

Compiled Languages

# C with compilation
runtools execute --lang c --code '
#include <stdio.h>
int main() {
    printf("Hello from C!\n");
    return 0;
}
'

# Rust
runtools execute --lang rust --code '
fn main() {
    let sum: i32 = (1..=100).sum();
    println!("Sum = {}", sum);
}
'

List Available Runtimes

runtools execute runtimes
Output:
Available runtimes:
  python          3.12.3       aliases: py, python3
  javascript      22.x.x       aliases: js, node
  typescript      22.x.x       aliases: ts
  bash            5.2.21       aliases: sh
  c               13.3.0       aliases: gcc
  c++             13.3.0       aliases: cpp, g++
  go              1.22.5       aliases: golang
  ruby            3.2.3        aliases: rb
  rust            1.82.0       aliases: rs
  java            21.0.x       aliases: jdk
  csharp          10.0.x       aliases: cs, dotnet

Exit Codes

The execute command exits with code 0 if the executed code succeeds (exit code 0), or code 1 if the code fails or an error occurs. This makes it compatible with shell scripting and CI/CD pipelines.