---
title: "Run a command inside the sandbox (`@vercel/sandbox`-compatible)."
method: POST
path: "/v1/sandboxes/{id}/cmd"
tags: ["Sandboxes"]
---

# Run a command inside the sandbox (\`@vercel/sandbox\`-compatible).

`POST /v1/sandboxes/{id}/cmd`

## Request

- Base URL: `/api` (relative, and the document was published on a file host, not at the API’s origin)
- URL: `/api/v1/sandboxes/{id}/cmd`
- Auth: HTTP bearer

`wait=false` (default) returns `{ command: {..., exitCode: null} }`
immediately once the background task is spawned.

`wait=true` streams `application/x-ndjson`: the first line is the
running envelope, the second is the finished envelope with `exitCode`.

## Path parameters

- `id` string, required

## Request body

- CmdBody
  - `args` string[]: Arguments to pass to the binary. Defaults to empty.
  - `command` string, required: Binary name (argv[0]) — e.g. `"ls"`, `"node"`. The SDK sends this separately from `args`.
  - `cwd` string, nullable: Working directory override.
  - `env` object: Extra env vars.
  - `sudo` boolean: When true, the SDK runs the command privileged. We ignore it today — the underlying provider always runs as the sandbox's own user.
  - `wait` boolean: When true, the response is an `application/x-ndjson` stream where the first line is the running-command envelope and the second line is the finished-command envelope with `exitCode`.

## Response `200`

Command started (wait=false) or finished (wait=true)

- CmdResponse: `@vercel/sandbox` envelope: `{ command: {...} }`.
  - `command` CmdInner, required: Inner `command` object — matches the SDK's zod validator exactly. `exitCode` is `null` until the command terminates; `startedAt` is Unix epoch milliseconds.
    - `args` string[], required
    - `cwd` string, required
    - `exitCode` integer, nullable
    - `id` string, required
    - `name` string, required
    - `sandboxId` string, required
    - `startedAt` integer, required

## Other responses

- `404`: Sandbox not found

## Changes

- **2026-04-25** `774be20905f2`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/gotempsh/apis/temps/changes/v1/sandboxes/:id/cmd/post.md)

---

[API](https://skmtc.dev/gotempsh/apis/temps.md) - [All operations](https://skmtc.dev/gotempsh/apis/temps/llms.txt) - [OpenAPI document](https://skmtc.dev/gotempsh/apis/temps/revisions/3b040526eb43?raw)
