---
title: "Run a command and stream its output"
description: "Runs one command and streams newline-delimited frames: stdout, stderr and drop frames, then one final exit or error frame."
canonical: "https://www.cool.computer/docs/api-reference/execution/run-a-command-and-stream-its-output"
---
# Run a command and stream its output

> Runs one command and streams newline-delimited frames: stdout, stderr and drop frames, then one final exit or error frame.

```http
POST https://api.cool.computer/api/computers/{id}/exec/stream
```

Runs one command and streams newline-delimited frames: stdout, stderr and drop frames, then one final exit or error frame. Every frame carries execution_id; omit it in the request and the server mints one, returned in the first frame, which attach and cancel accept. stdin_base64 is written to the command's standard input. A site with no VM answers 409 needs_vm; give it its own VM first with POST /api/computers/{id}/vm. Callers: an account bearer of the owner or of someone the computer is shared with.

## Authorization

- A Cool Computers API key, user access token, or claimed agent access token in the Authorization header. Follow https://www.cool.computer/auth.md for agent registration and https://www.cool.computer/authentication.md for direct user credentials.

## Parameters

- `id` (path, string, at least 1 characters, required): The computer's name, such as agent-atlas, or its id (cmp_…). Every caller may use either, the computer's own runtime token included.

## Request body

Required.

- `application/json` (object)
  - `execution_id` (string, pattern `^cmp_[0-9a-f]{24}\.exec\.[0-9a-f]{32}$`): Optional caller identity bound to the target computer. Omit it and the server mints one, returned in the first frame.
  - `after_id` (integer, at least 0)
  - `command` (string, at least 1 characters, required)
  - `cwd` (string): Existing absolute directory without symlinks.
  - `uid` (integer, at least 0)
  - `gid` (integer, at least 0)
  - `shell` (string or null)
  - `stdin_base64` (string): Standard input, base64-encoded.
  - `env` (object)
    - `*` (string): Each value, under a name of the caller's.

## Responses

- `200`: Newline-delimited output frames and one final result.
  - `application/x-ndjson` (object)
    - `execution_id` (string, pattern `^cmp_[0-9a-f]{24}\.exec\.[0-9a-f]{32}$`, required)
    - `id` (integer, at least 1): Monotonic replay cursor present only on stdout, stderr, and drop frames.
    - `timestamp` (string, date-time)
    - `type` ("pid" or "stdout" or "stderr" or "drop" or "exit" or "error", required)
    - `status` ("running" or "succeeded" or "failed" or "cancelled" or "owner_lost")
    - `pid` (integer, at least 1)
    - `stdout` (string)
    - `stderr` (string)
    - `dropped_bytes` (integer, at least 0)
    - `dropped_frames` (integer, at least 0)
    - `exit_code` (integer)
    - `signal` (string)
    - `code` (string)
    - `error` (string)
    - Exactly one of: `status` ("running") and `pid` and `type` ("pid"), without `id`; `id` and `stdout` and `type` ("stdout"); `id` and `stderr` and `type` ("stderr"); `id` and `dropped_bytes` and `dropped_frames` and `type` ("drop"); `status` and `exit_code` and `type` ("exit"), without `id`; `code` and `error` and `type` ("error"), without `id`
- `400`: Bad Request.
- `401`: Unauthorized.
- `402`: Payment Required. `pro_required`: VMs need Pro; start Pro with cool billing upgrade, or fix a lapsed subscription with cool billing portal, or use the Account page.
- `403`: Forbidden.
- `404`: Not Found. `computer_not_found`: the computer does not exist or is not yours.
- `409`: Conflict.
- `413`: Payload Too Large.
- `429`: Too Many Requests. If the problem code is api_request_rate_exceeded, wait for Retry-After seconds; other problem codes describe a separate limit.
- `500`: Internal Server Error.
- `503`: Service Unavailable. `computer_starting` means the computer is starting, or stopped and being started again; wait for Retry-After seconds, then retry. Otherwise inspect the problem code and resolution.
- `default`: A machine-readable API error with a stable code and recovery instruction.

An error is an `application/problem+json` document with a stable `code`; [API errors](/docs/api-reference/errors) says how to handle one.

## Example

```sh
curl -X POST "https://api.cool.computer/api/computers/$PARAM_ID/exec/stream" \
  -H "authorization: Bearer $TOKEN" \
  -H "content-type: application/json" \
  --data '{"command":"echo hello"}'
```
