---
title: "Run a command"
description: "Runs one command inside a computer and waits for its stdout, stderr, and exit status: curl -X POST -H 'authorization: Bearer $TOKEN' -H 'content-type: application/json' --data '{\"command\":\"uname -a\"}'…"
canonical: "https://www.cool.computer/docs/api-reference/execution/run-a-command"
---
# Run a command

> Runs one command inside a computer and waits for its stdout, stderr, and exit status: curl -X POST -H 'authorization: Bearer $TOKEN' -H 'content-type: application/json' --data '{"command":"uname -a"}'…

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

Runs one command inside a computer and waits for its stdout, stderr, and exit status: curl -X POST -H 'authorization: Bearer $TOKEN' -H 'content-type: application/json' --data '{"command":"uname -a"}' https://api.cool.computer/api/computers/{id}/exec. The response's execution_id names the run for attach and cancel, and a failure after the command may have started carries it in the problem's context.execution_id; a cwd must be an absolute path to an existing directory; a command that cannot start because its cwd is missing or is a file answers 400 invalid_cwd. A site with no VM answers 409 needs_vm and changes nothing; give it its own VM first with POST /api/computers/{id}/vm. To run something on a schedule, create a systemd timer with this endpoint, for example `sudo systemd-run --uid=runtime --on-calendar='*:0/15' --unit=report /home/runtime/report.sh`; the image has no cron, and timers reach the network the same way exec does.

## 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. Omit it and the server mints one and returns it. Send your own, the computer's id followed by .exec. and 32 lowercase hex characters, when a retry must reattach to the same run instead of starting the command again.
  - `command` (string, at least 1 characters, required)
  - `cwd` (string): Absolute path to an existing directory; a relative one, or one missing or a file when the command fails to start, answers 400 invalid_cwd. A path through a symlink works.
  - `uid` (integer, at least 0)
  - `gid` (integer, at least 0)
  - `shell` (string or null)
  - `env` (object)
    - `*` (string): Each value, under a name of the caller's.

## Responses

- `200`: Completed command output.
  - `application/json` (object)
    - `execution_id` (string, pattern `^cmp_[0-9a-f]{24}\.exec\.[0-9a-f]{32}$`, required)
    - `status` ("succeeded" or "failed" or "cancelled" or "owner_lost", required)
    - `stdout` (string, required): Retained stdout. Check dropped_bytes and dropped_frames before treating it as complete.
    - `stderr` (string, required): Retained stderr. Check dropped_bytes and dropped_frames before treating it as complete.
    - `exit_code` (integer, required)
    - `signal` (string)
    - `error` (string): Explicit owner or launch failure when status is owner_lost or failed.
    - `dropped_bytes` (integer, at least 0)
    - `dropped_frames` (integer, at least 0)
- `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" \
  -H "authorization: Bearer $TOKEN" \
  -H "content-type: application/json" \
  --data '{"command":"uname -a"}'
```
