---
title: "Execute a sandbox command"
method: POST
path: "/api/v2/sandboxes/{sandbox_id}/execute"
tags: ["sandboxes"]
---

# Execute a sandbox command

`POST /api/v2/sandboxes/{sandbox_id}/execute`

## Request

- Base URL: `https://api.smith.langchain.com`
- URL: `https://api.smith.langchain.com/api/v2/sandboxes/{sandbox_id}/execute`
- Auth: one of:
  - API key in header `X-API-Key`
  - API key in header `X-Tenant-Id`
  - HTTP bearer

Execute a command inside a sandbox and return stdout, stderr, and exit code. Use the streaming execute endpoints for long-running commands that may exceed the synchronous request deadline.

## Path parameters

- `sandbox_id` string, required

## Request body

- SandboxesExecRequest
  - `command` string[]: Command accepts either a shell command string or an argv string array.
  - `cwd` string: Deprecated: use run_config.work_dir. Rejected when run_config is also set.
  - `env` object: Deprecated: use run_config.env_vars. Rejected when run_config is also set.
  - `run_config` SandboxapiRunConfig
    - `env_vars` object
    - `user` string
    - `work_dir` string
  - `shell` string
  - `timeout_seconds` integer

## Response `200`

OK

- SandboxesExecResponse
  - `exit_code` integer
  - `stderr` string
  - `stdout` string

## Other responses

- `400`: Bad Request
- `403`: Forbidden
- `404`: Not Found
- `409`: The sandbox closed its connection during execution
- `422`: Synchronous execution exceeded the request deadline
- `500`: Internal Server Error

## Changes

- **2026-10-16** `1a8ee9358d81`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/langchain-ai/apis/langsmith/changes/api/v2/sandboxes/:sandbox_id/execute/post.md)

---

[API](https://skmtc.dev/langchain-ai/apis/langsmith.md) - [All operations](https://skmtc.dev/langchain-ai/apis/langsmith/llms.txt) - [OpenAPI document](https://skmtc.dev/langchain-ai/apis/langsmith/revisions/7a01c01f75e8?raw)
