Execute a command
POST
https://api.vercel.com/v2/sandboxes/sessions/{sessionId}/cmdExecutes 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.https://api.vercel.com/v2/sandboxes/sessions/{sessionId}/cmd
const response = await fetch('https://api.vercel.com/v2/sandboxes/sessions/sessionId/cmd?cmdId=string&teamId=string&slug=string', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_ACCESS_TOKEN', 'Content-Type': 'application/json', }, body: JSON.stringify({ "command": "npm", "args": [], "cwd": "/home/vercel-sandbox", "env": "[object Object]", "sudo": "true", "wait": "true", "logs": "true", "timeout": "30000", "attachStdin": "true" }),});
const data = await response.json();console.log(data);Response
{ "command": { "args": [], "cwd": "/vercel/sandbox", "durationMs": "1234", "exitCode": "0", "id": "cmd_123a6c5209bc3778245d011443644c8d27dc2c50", "name": "npm", "sessionId": "sbx_123a6c5209bc3778245d011443644c8d27dc2c50", "startedAt": "1673123456789" }}AuthorizationbearerToken
Default authentication mechanism
application/json
The executable or shell command to run. This is the program name without arguments.
Arguments to pass to the command. Each argument should be a separate array element.
The working directory in which to execute the command. Defaults to the sandbox home directory if not specified.
Additional environment variables to set for this command. These are merged with the sandbox environment.
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.
If true, stream the logs of the command execution in real-time via ND-JSON. This is only applicable if
wait is also true.Maximum duration in milliseconds the command may run before it is killed with SIGKILL, up to 5 hours. Enforced at exec time, independently of
wait.400One of the provided values in the request body is invalid.
One of the provided values in the request query is invalid.
401The request is not authorized.
403You do not have permission to access this resource.
404Error
410Error
422Error
429Error
500Error