# exec_run

Run one command on the machine and wait for it: exit code, stdout and stderr apart, whether it timed out. A non-zero exit is a normal result, not an error. Default timeout 120 s (at most 600); on timeout the whole process group is stopped. Output keeps the last 64 KiB of each stream; longer output is saved to stdout_file / stderr_file. The command gets a small base environment (PATH, HOME, USER, SHELL, the locale, the desktop session) plus `env`; nothing else of cmdop's own environment reaches it. For long or interactive work use task_start instead.

**In short:** Risk class [`exec`](https://docs.cmdop.ai/reference/tools.md#risk-classes). Over MCP call `exec_run`; over HTTP send `"tool": "exec_run"` to [`POST /api/v1/call`](https://docs.cmdop.ai/reference/http/post-call.md).

## Arguments

Over MCP every tool also takes `machine`: the machine's name or id, optional when only one machine is online.

| Name | Type | Required | Meaning |
| --- | --- | --- | --- |
| `argv` | `string[]` | no | Program and arguments, run directly without a shell. Give this or `command`. |
| `command` | `string` | no | A shell command line, run as `/bin/sh -c <command>`. Give this or `argv`. |
| `cwd` | `string` | no | Working folder. Default: the user's home folder. |
| `env` | `object` | no | Extra environment variables for this command. Default: `{}`. |
| `stdin` | `string` | no | Text written to the command's standard input, then closed. Default: no input. |
| `timeout_secs` | `integer` | no | Seconds before the command is stopped (default 120, at most 600). |

## Result

| Name | Type | Required | Meaning |
| --- | --- | --- | --- |
| `cancelled` | `boolean` | yes | Stopped because the call was cancelled. |
| `duration_ms` | `integer` | yes |  |
| `exit_code` | `integer` | no | Exit code; absent when the command was ended by a signal. |
| `signal` | `integer` | no | The signal that ended it (Unix). |
| `stderr` | `string` | yes | The end of standard error, at most 64 KiB. |
| `stderr_file` | `string` | no | When stderr was longer than 64 KiB: a file on the machine with all of it (up to 100 MiB), readable with fs_read. |
| `stdout` | `string` | yes | The end of standard output, at most 64 KiB, as text (invalid UTF-8 replaced). |
| `stdout_file` | `string` | no | When stdout was longer than 64 KiB: a file on the machine with all of it (up to 100 MiB), readable with fs_read. |
| `timed_out` | `boolean` | yes | Stopped because it ran longer than `timeout_secs`. |
| `truncated` | `boolean` | yes | Output was longer than what is returned; the whole of it is in the files below. |

## Examples

**MCP**

```json
{
  "name": "exec_run",
  "arguments": {
    "machine": "<machine>"
  }
}
```

**HTTP**

```bash
curl -sS -X POST "https://<contour>.cmdop.ai/api/v1/call" \
  -H "Authorization: Bearer $CMDOP_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"machine":"<machine>","tool":"exec_run","args":{}}'
```

## Limits

The call times out after 620 s (`timed_out`). Available since version 0.0.1. A refused or failed call returns one of the [error codes](https://docs.cmdop.ai/reference/errors.md).
