Skip to main content

Execute Python Code

curl -X POST http://localhost:8002/api/v1/execute \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "print(\"Hello, World!\")\nprint(2 + 2)",
    "language": "python"
  }'
Response:
{
  "execution_id": "exec-123",
  "stdout": "Hello, World!\n4\n",
  "stderr": "",
  "exit_code": 0,
  "execution_time": 0.123,
  "language": "python"
}

Execute JavaScript

curl -X POST http://localhost:8002/api/v1/execute \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "console.log(\"Hello from Node.js\");",
    "language": "javascript"
  }'

With Standard Input

curl -X POST http://localhost:8002/api/v1/execute \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "name = input(\"Enter name: \")\nprint(f\"Hello, {name}!\")",
    "language": "python",
    "stdin": "Nadoo"
  }'

With Custom Timeout

curl -X POST http://localhost:8002/api/v1/execute \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "import time\ntime.sleep(5)\nprint(\"Done!\")",
    "language": "python",
    "timeout": 10
  }'

Async Execution

# Submit code
curl -X POST http://localhost:8002/api/v1/execute/async \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "print(\"Async execution\")",
    "language": "python"
  }'

# Get status
curl http://localhost:8002/api/v1/execute/status/exec-123 \
  -H "X-API-Key: your-api-key"

Next Steps