---
title: "Execute a command inside a sandbox"
method: POST
path: "/sandboxes/{sandbox_id}/exec"
tags: ["Exec"]
---

# Execute a command inside a sandbox

`POST /sandboxes/{sandbox_id}/exec`

Runs a command inside the sandbox and waits for it to finish, returning
stdout, stderr, and exit code. Idle sandboxes are automatically resumed
before execution.

## Request body

- ExecRequest
  - `command` string, required — Command to execute. Wrapped in `/bin/sh -c` unless `args` is provided.
  - `args` string[] — If provided, `command` is used as the binary and `args` as arguments (no shell wrapping).
  - `env` object — Environment variables for the command.
  - `working_dir` string — Working directory (default /home/user).
  - `timeout_s` integer — Timeout in seconds.

## Response `200`

Command executed

- ExecResult
  - `stdout` string
  - `stderr` string
  - `exit_code` integer

## Other responses

- `401` — Missing or invalid API key
- `404` — Resource not found
- `409` — Sandbox is not in a valid state for this operation
- `500` — Internal server error

---

[API](https://skmtc.net/superserve-ai/apis/superserve-api.md) · [All operations](https://skmtc.net/superserve-ai/apis/superserve-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/superserve-ai/superserve-api/revisions/304fe18155b8/schema)
