---
title: "POST /v1/sandboxes/{id}/execute_async"
method: POST
path: "/v1/sandboxes/{id}/execute_async"
---

# POST /v1/sandboxes/{id}/execute_async

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

Execute command with streaming output.

Executes a long-running command in a sandbox and streams stdout/stderr in real-time.

**Response Format**: NDJSON (Newline Delimited JSON) - each line is a JSON object.

**Streaming Behavior**:
- Output chunks are sent as they're produced by the command
- When the command completes, a final chunk with `exit_code` is sent

**Client Disconnection**:
- When the client closes the connection, the running process is automatically terminated

**Example Client Code**:
```typescript
const response = await fetch(url, { method: 'POST', body: JSON.stringify({ command: 'npm run dev' }) });
const reader = response.body.getReader();
const decoder = new TextDecoder();

while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  const lines = decoder.decode(value).split('\n').filter(Boolean);
  for (const line of lines) {
    const { stdout, stderr, exit_code } = JSON.parse(line);
    if (stdout) process.stdout.write(stdout);
    if (stderr) process.stderr.write(stderr);
  }
}
```

## Path parameters

- `id` string, required — Sandbox ID

## Request body

- ExecuteAsyncRequest
  - `command` string, required — Command to execute (full CLI command, supports shell features like redirection, pipes, etc.)
  - `env` object — Environment variables to set for the command
  - `working_dir` string — Working directory for execution

## Response `200`

Streaming response with NDJSON chunks containing stdout/stderr. Each line is a JSON object.

## Other responses

- `400` — Bad request - missing required parameters
- `403` — Forbidden - Sandbox does not belong to user
- `404` — Sandbox not found
- `500` — Execution error

## Changes

- **2025-12-03** `4e73081be406` — 1 info
  - endpoint added

[Change history](https://skmtc.dev/avm-codes/apis/avm-sandbox-platform-api/changes/v1/sandboxes/:id/execute_async/post.md)

---

[API](https://skmtc.dev/avm-codes/apis/avm-sandbox-platform-api.md) · [All operations](https://skmtc.dev/avm-codes/apis/avm-sandbox-platform-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/avm-codes/avm-sandbox-platform-api/revisions/260daed67193/schema)
