Skip to main content
Execute code synchronously in the sandbox. The request waits until execution completes and returns the output.

Endpoint

POST /execute

Request

Headers

Authorization: Bearer YOUR_JWT_TOKEN
Content-Type: application/json

Body Parameters

ParameterTypeRequiredDescription
codestringYesCode to execute
languagestringNoLanguage: python, javascript, bash, go (default: python)
timeoutintegerNoExecution timeout in seconds (default: 60, max: 300)
working_dirstringNoWorking directory (default: /workspace)
envobjectNoEnvironment variables for this execution only

Example Request

Execute Python code:
curl -X POST https://sandbox_abc123xyz.hopx.dev/execute \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "print(\"Hello from HopX!\")",
    "language": "python"
  }'
Execute JavaScript code:
curl -X POST https://sandbox_abc123xyz.hopx.dev/execute \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "console.log(\"Hello from Node.js!\");",
    "language": "javascript"
  }'
Execute with custom environment:
curl -X POST https://sandbox_abc123xyz.hopx.dev/execute \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "import os; print(os.getenv(\"MY_VAR\"))",
    "language": "python",
    "env": {
      "MY_VAR": "my_value"
    }
  }'

Response

Success (200 OK)

{
  "success": true,
  "stdout": "Hello from HopX!\n",
  "stderr": "",
  "exit_code": 0,
  "execution_time": 0.15
}

Response Fields

FieldTypeDescription
successbooleanWhether execution completed successfully
stdoutstringStandard output
stderrstringStandard error
exit_codeintegerExit code (0 = success)
execution_timenumberExecution time in seconds

Status Codes

CodeDescription
200Execution completed
400Invalid request (missing code, invalid language)
401Unauthorized (invalid or expired JWT)
408Execution timeout
500Execution failed

Supported Languages

Python

curl -X POST https://sandbox_abc123xyz.hopx.dev/execute \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "import pandas as pd\ndf = pd.DataFrame({\"a\": [1,2,3]})\nprint(df)",
    "language": "python"
  }'

JavaScript (Node.js)

curl -X POST https://sandbox_abc123xyz.hopx.dev/execute \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "const fs = require(\"fs\");\nconsole.log(fs.readdirSync(\".\"));",
    "language": "javascript"
  }'

Bash

curl -X POST https://sandbox_abc123xyz.hopx.dev/execute \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "ls -la /workspace",
    "language": "bash"
  }'

Errors

Timeout (408)

{
  "error": "Execution timeout after 60 seconds",
  "code": "EXECUTION_TIMEOUT"
}
Cause: Code execution exceeded the timeout limit. Fix: Increase the timeout or optimize your code.

Invalid Language (400)

{
  "error": "Invalid language: ruby",
  "code": "INVALID_REQUEST"
}
Cause: Unsupported language specified. Fix: Use one of the supported languages: python, javascript, bash, go.

Execution Failed (500)

{
  "success": false,
  "stdout": "",
  "stderr": "NameError: name 'x' is not defined\n",
  "exit_code": 1,
  "execution_time": 0.05
}
Cause: Code execution failed (syntax error, runtime error, etc.). Fix: Check the stderr field for error details.

Use Cases

Data Analysis

curl -X POST https://sandbox_abc123xyz.hopx.dev/execute \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "import pandas as pd\nimport numpy as np\n\ndata = {\"sales\": [100, 150, 200, 180, 220]}\ndf = pd.DataFrame(data)\n\nprint(f\"Mean: ${df[\"sales\"].mean():.2f}\")\nprint(f\"Median: ${df[\"sales\"].median():.2f}\")",
    "language": "python"
  }'

File Processing

curl -X POST https://sandbox_abc123xyz.hopx.dev/execute \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "with open(\"/workspace/data.txt\", \"r\") as f:\n    lines = f.readlines()\n    print(f\"File has {len(lines)} lines\")",
    "language": "python"
  }'

System Information

curl -X POST https://sandbox_abc123xyz.hopx.dev/execute \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "import platform\nimport os\n\nprint(f\"OS: {platform.system()}\")\nprint(f\"Python: {platform.python_version()}\")\nprint(f\"CPU Count: {os.cpu_count()}\")",
    "language": "python"
  }'

Next Steps