Skip to main content
Execute shell commands in a running sandbox.

Endpoint

POST {sandbox_public_host}/commands/run

Authentication

Authorization: Bearer {auth_token}

Request

Request Body

{
  "command": "ls -la /workspace",
  "timeout": 30,
  "working_dir": "/workspace",
  "env": {
    "API_KEY": "sk-test-123"
  }
}

Response

{
  "stdout": "total 8\ndrwxr-xr-x 2 root root 4096 Jan 15 10:30 .",
  "stderr": "",
  "exit_code": 0,
  "execution_time": 0.045
}

Examples

cURL

curl -X POST https://1761048129dsaqav4n.hopx.dev/commands/run \
  -H "Authorization: Bearer {auth_token}" \
  -H "Content-Type: application/json" \
  -d '{
    "command": "ls -la /workspace",
    "timeout": 30
  }'

Python

import requests

data = {
    "command": "ls -la /workspace",
    "timeout": 30,
    "working_dir": "/workspace"
}

response = requests.post(
    f"{sandbox_public_host}/commands/run",
    headers={"Authorization": f"Bearer {auth_token}"},
    json=data
)

result = response.json()
print(f"Output: {result['stdout']}")
print(f"Exit code: {result['exit_code']}")

JavaScript

const response = await fetch(`${sandboxPublicHost}/commands/run`, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${authToken}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    command: 'ls -la /workspace',
    timeout: 30
  })
});

const result = await response.json();
console.log(`Output: ${result.stdout}`);
console.log(`Exit code: ${result.exit_code}`);