---
title: "Execute a command"
method: POST
path: "/v2/sandboxes/sessions/{sessionId}/cmd"
tags: ["sandboxes"]
---

# Execute a command

`POST /v2/sandboxes/sessions/{sessionId}/cmd`

Executes a shell command inside a running session. The command runs asynchronously and returns immediately with a command ID that can be used to track its progress and retrieve its output. Optionally, use the `wait` parameter to stream the command status until completion.

## Path parameters

- `sessionId` string, required — The unique identifier of the session in which to execute the command.

## Query parameters

- `cmdId` string, required — The unique identifier of the command to stream logs for.
- `teamId` string
- `slug` string

## Request body

- object
  - `command` string, required — The executable or shell command to run. This is the program name without arguments.
  - `args` string[] — Arguments to pass to the command. Each argument should be a separate array element.
  - `cwd` string — The working directory in which to execute the command. Defaults to the sandbox home directory if not specified.
  - `env` object — Additional environment variables to set for this command. These are merged with the sandbox environment.
  - `sudo` boolean — Execute the command with root (superuser) privileges.
  - `wait` boolean — If true, returns an ND-JSON stream that emits the command status when started and again when finished. Useful for synchronously waiting for command completion.
  - `logs` boolean — If true, stream the logs of the command execution in real-time via ND-JSON. This is only applicable if `wait` is also true.
  - `timeout` integer — Maximum duration in milliseconds the command may run before it is killed with SIGKILL. Enforced at exec time, independently of `wait`.

## Response `200`

- object
  - `command` SessionCommand, required — This object represents a command run in a Vercel Sandbox session (v2 API).
    - `id` string, required — The ID of the command.
    - `name` string, required — The name of the command.
    - `args` string[], required — The arguments of the command.
    - `cwd` string, required — The current working directory of the command.
    - `sessionId` string, required — The ID of the session associated with the command.
    - `exitCode` number, nullable, required — If the command did finish, the exit code.
    - `startedAt` number, required — When the command was started, in milliseconds since the epoch.
    - `durationMs` number — Duration of the command execution in milliseconds.

## Other responses

- `400` — One of the provided values in the request body is invalid. One of the provided values in the request query is invalid.
- `401` — The request is not authorized.
- `403` — You do not have permission to access this resource.
- `404`
- `410`
- `422`
- `429`
- `500`

---

[API](https://skmtc.net/vercel/apis/api.md) · [All operations](https://skmtc.net/vercel/apis/api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/vercel/api/versions/61d1ba3f6dac/schema)
