--- title: "Execute command" description: "Run a command inside a sandbox" --- Endpoint: `POST /api/v1/sandboxes/{name}/exec` ```bash cURL curl -X POST "$BASE/api/v1/sandboxes/my-sandbox/exec?namespace=default" \ -H "X-API-Key: $K7_API_KEY" \ -H "Content-Type: application/json" \ -d '{"command": "echo Hello"}' ``` ```json Success { "data": { "exit_code": 0, "stdout": "Hello\n", "stderr": "", "duration_ms": 12 } } ``` Sandbox name Namespace Shell command to execute ### Semantics - `exit_code`: `0` on success, non-zero when the command fails. - `stdout`/`stderr`: Raw streams captured from the process; may include newlines. - `duration_ms`: Client-observed duration including stream lifecycle. ### Examples ```bash curl -X POST "$BASE/api/v1/sandboxes/my-sandbox/exec?namespace=default" \ -H "Authorization: Bearer $K7_API_KEY" \ -H "Content-Type: application/json" \ -d '{"command": "apk add --no-cache curl && curl -I https://example.com"}' ``` Error example (non-zero exit): ```json { "data": { "exit_code": 2, "stdout": "", "stderr": "some error...", "duration_ms": 37 } } ```