> ## Documentation Index
> Fetch the complete documentation index at: https://vetta.sh/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Shell

> The bash tool runs a command in the sandbox and returns buffered stdout, stderr, and an exit code.

The **`bash`** tool is how the agent runs commands on the [computer](https://vetta.sh/docs/computer/index.md). Each call executes `bash -c <command>` in a **non-login shell**; to run somewhere else, `cd` inside the command. `exec` is a single request/response; the [streamed exec](https://vetta.sh/docs/api/computers.md#stream-a-command) delivers the same run as it happens.

> [!NOTE]
>
> Exec on a **paused** computer resumes it first, and it stays running (and billed) afterwards. See [lifecycle](https://vetta.sh/docs/computer/sandbox.md#lifecycle).

## Examples

```bash CLI theme={"system"}
naive computer exec cmp_01a02ad8ba0f7bd59115bfd513fc6ed7 -- "ls -la ~"

# with a timeout; cd inside the command, there is no --cwd
naive computer exec cmp_01a02ad8ba0f7bd59115bfd513fc6ed7 --command "cd ~ && npm test" --timeout-ms 30000
```

```typescript TypeScript theme={"system"}
const result = await naive.computers.exec(computer.id, "cd ~ && CI=1 npm test", 30_000); // timeout in ms

console.log(result.exit_code, result.stdout);
```

```bash cURL theme={"system"}
curl https://api.vetta.sh/v1/computers/$COMPUTER_ID/exec \
  -H "Authorization: Bearer $NAIVE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "command": "cd ~ && CI=1 npm test",
    "timeout_ms": 30000
  }'
```

## Output caps at a glance

| Field | Cap | Behavior beyond cap |
| - | - | - |
| `stdout` | 262,144 chars | Truncated |
| `stderr` | 262,144 chars | Truncated |

> [!TIP]
>
> When you expect large output, redirect it to a file (`… > ~/out.log 2>&1`) and read the parts you need with the [filesystem](https://vetta.sh/docs/computer/filesystem.md) tools instead of returning it all through `stdout`.

## Fields

**command** `string` *required*

The command line to run. Executed as `bash -c <command>`.

**timeout\_ms** `integer`

Maximum time to wait before the command is killed and the call returns. Defaults to `30000`, up to `600000`. When it elapses, `exit_code` is `124` and `timed_out` is `true`.

> [!WARNING]
>
> There is no `cwd` or `env` field: `cd` and set variables inside the command (`cd ~ && CI=1 npm test`); they last for that call only. There is no way to bake environment variables into a computer at create time. With the coming egress pinning, secrets are supplied by the [vault](https://vetta.sh/docs/identity/vault.md) at the network boundary rather than as sandbox env vars — see [Networking](https://vetta.sh/docs/computer/networking.md#egress-pinning-coming-soon).

## Response

The command is run to completion and its output is **buffered**, then returned together:

**stdout** `string`

Buffered standard output. Capped at **262,144 characters**; output beyond the cap is cut, and `truncated` is `true`.

**stderr** `string`

Buffered standard error, capped at **262,144 characters** independently of `stdout`.

**exit\_code** `integer`

The process exit code; `124` when `timeout_ms` elapsed.

**duration\_ms** `integer`

How long the command ran, in milliseconds.

**timed\_out** `boolean`

`true` when the command was killed at `timeout_ms`.

**truncated** `boolean`

`true` when `stdout` or `stderr` was cut at the cap.

> [!NOTE]
>
> `exec` is **not streaming**: stdout and stderr are collected in full (up to the cap) and returned once the command exits or `timeout_ms` elapses. To read output as it is produced, use the [streamed exec](https://vetta.sh/docs/api/computers.md#stream-a-command) (`computers.execStream(id, command, { timeoutMs })` in the SDK). For long-running work, have the command write progress to a file and poll it with [`read`](https://vetta.sh/docs/computer/filesystem).

> [card] [Next: browser](https://vetta.sh/docs/computer/browser.md)
>
> Drive a real, managed browser scoped to an allow-list of domains.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.