---
title: "POST /v1/sandbox/{chatId}/exec"
description: "Run a shell command — Runs a shell command in your chat's isolated code sandbox and returns its output."
full: true
---

**Auth:** required. Send an `ivy_` API key (`Authorization: Bearer ivy_…` or `X-Ivy-Api-Key`), a Clerk session JWT (`Authorization: Bearer …`) or the Clerk `__session` cookie (browser sessions). See [Authentication](/docs/api/authentication).

Runs a shell command in your chat's isolated code sandbox and returns its output. The working directory defaults to `/workspace` and the timeout defaults to 30 seconds; requested timeouts above 120 seconds are clamped to 120.

Returns 503 `SANDBOX_NOT_READY` while the sandbox is still starting; retry after the `Retry-After` interval.

## Request

#### Path parameters

- `chatId` (string) —
ID of the chat that owns the sandbox

#### Request body

- `command` (string) —
Shell command to run

- `timeout` (integer) —
Time budget in seconds. Defaults to 30; values above 120 are clamped to 120.

- `workdir` (string) —
Working directory. Defaults to `/workspace`.

## Responses

### `200` OK

Command finished (a non-zero `exitCode` is still HTTP 200)

Response shape:

- `stdout` (string) —

- `stderr` (string) —

- `exitCode` (integer) —
Process exit code; 0 means success

- `duration_ms` (integer) —
Run time in milliseconds

### `400` Bad Request

Invalid request

Response shape: `object`

### `401` Unauthorized

Authentication required

Response shape: `object`

### `403` Forbidden

You do not own this chat, or your key's project scope excludes it

Response shape: `object`

### `404` Not Found

Resource not found

Response shape: `object`

### `429` Too Many Requests

Rate limit exceeded

Response shape: `object`

### `502` Bad Gateway

The sandbox returned a malformed response

Response shape: `object`

### `503` Service Unavailable

The sandbox is still starting; retry shortly

Response shape: `object`

### `504` Gateway Timeout

The command exceeded its time budget

Response shape: `object`

**curl**

```bash
curl -X POST 'https://ivybiosciences.com/api/v1/sandbox/{chatId}/exec' \
  -H "Authorization: Bearer $IVY_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "command": ""
}'
```

**JavaScript**

```js
const res = await fetch('https://ivybiosciences.com/api/v1/sandbox/{chatId}/exec', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.IVY_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
  "command": ""
}),
});
const data = await res.json();
```

**Python**

```python
import os, requests

res = requests.post(
    "https://ivybiosciences.com/api/v1/sandbox/{chatId}/exec",
    headers={"Authorization": f"Bearer {os.environ['IVY_API_KEY']}"},
    json={
  "command": ""
},
)
data = res.json()
```
