cortex run

Execute code files in sandboxed environments with resource limits, or as direct subprocesses. Supports auto-fix loop for failed executions.

Usage

cortex run <file>                    # Run in sandbox (auto-detect language)
cortex run script.py --no-sandbox    # Run as direct subprocess
cortex run script.py --fix           # Enable LLM auto-fix loop on failure
cortex run script.py --fix --max-fix 6  # Up to 6 fix attempts

Options

OptionDescription
--no-sandboxRun as direct subprocess instead of Docker sandbox
--fixEnable LLM auto-fix loop when code fails
--max-fixMaximum number of fix attempts (default: 4)
--helpShow help for this command

Supported Languages

LanguageExtensionSandbox Image
Python.pypython:3.12-slim
JavaScript.jsnode:22-slim
TypeScript.tsnode:22-slim
Bash.shubuntu:24.04
Ruby.rbruby:3.3-slim
Go.gogolang:1.23-bookworm
Rust.rsrust:1.78-slim

Docker Sandbox

When running in sandbox mode, Docker containers are created with:

ConstraintValue
Network--network=none (no network access)
Memory256MB limit
CPU0.5 cores
Process limit64 PIDs
Securityno-new-privileges
Timeout30 seconds
Max output64KB

Subprocess fallback is used when docker info fails.

Auto-Fix Loop

When --fix is enabled:

runInSandbox(code)
  → exit != 0?
     → LLM: "Fix this error: <stderr>\n\nCode:\n<code>"
     → extract fixed code from LLM response
     → runInSandbox(fixedCode)
     → repeat up to maxRounds

Examples

# Run a Python script in Docker sandbox
cortex run analyze.py

# Run a shell script as direct subprocess
cortex run deploy.sh --no-sandbox

# Run with auto-fix enabled
cortex run buggy-code.py --fix

# Run with aggressive auto-fix
cortex run complex.js --fix --max-fix 8