Everstack
API ReferenceSandboxExecute Sandbox

Execute Sandbox Command

POST/v1/sandbox/{sandbox_id}/command
POST/v1/sandbox/{'{sandbox_id}'}/command

Your instance endpoint, shown on the instance page in the dashboard. Each instance has its own host; there is no shared API host.

Description

Executes a shell command inside the specified sandbox. By default the response is a Server-Sent Events (SSE) stream that emits stdout, stderr, and exit events in real time as the command runs.

When background is set to true, the command is launched in the background and the response immediately returns a command ID and status that can be used to poll for results.

Path Parameters

ParameterTypeRequiredDescription
sandbox_idstringYesSandbox ID or name

Request Body

PropertyTypeRequiredDescription
commandstringYesShell command to execute
cwdstringNoWorking directory for the command. Defaults to the sandbox root
backgroundbooleanNoRun the command in the background and return immediately. Default: false
timeoutintegerNoTimeout in milliseconds before the command is killed. Default: 30000

Responses

200 Success (foreground — SSE stream)

Each line is a JSON-encoded SSE event:

PropertyTypeDescription
typestringEvent type: "stdout", "stderr", or "exit"
datastringEvent payload. For "exit" events, contains the numeric exit code as a string

200 Success (background — background: true)

PropertyTypeDescription
idstringUnique ID for the background command
statusstringInitial status, e.g. "running"

default An unexpected error response.

PropertyTypeDescription
codeinteger
messagestring
detailsobject[]

Request

curl -X POST "https://{instance}.{region}.everstack.ai/v1/sandbox/{sandbox_id}/command" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: text/event-stream" \
  -d '{"command":"ls -la /workspace","cwd":"/workspace","background":false,"timeout":30000}'
const sandboxId = "your-sandbox-id";
const response = await fetch(`https://{instance}.{region}.everstack.ai/v1/sandbox/${sandboxId}/command`, {
  method: "POST",
  headers: {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json",
    "Accept": "text/event-stream",
  },
  body: JSON.stringify({
    "command": "ls -la /workspace",
    "cwd": "/workspace",
    "background": false,
    "timeout": 30000,
  }),
});

const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  console.log(decoder.decode(value));
}
import requests

sandbox_id = "your-sandbox-id"
response = requests.post(
    f"https://{instance}.{region}.everstack.ai/v1/sandbox/{sandbox_id}/command",
    headers={
        "Authorization": "Bearer YOUR_API_KEY",
        "Content-Type": "application/json",
        "Accept": "text/event-stream",
    },
    json={
        "command": "ls -la /workspace",
        "cwd": "/workspace",
        "background": False,
        "timeout": 30000,
    },
    stream=True,
)

for line in response.iter_lines():
    if line:
        print(line.decode("utf-8"))

Response

{"type":"stdout","data":"total 48\ndrwxr-xr-x 6 root root 4096 Jan  1 00:00 .\n"}
{"type":"stderr","data":""}
{"type":"exit","data":"0"}
{
  "code": 0,
  "message": "string",
  "details": [
    {
      "@type": "string"
    }
  ]
}