---
title: "pols exec"
description: "Run a command in a sandbox, streaming its output"
---

<!-- Generated by scripts/reference.mjs from the pols CLI's --help. Do not edit; run `npm run reference:sync`. -->

Run a command in a running sandbox as the sandbox user (uid 1000, passwordless
sudo), or as root with `--root`. Output streams as it is produced and pols exits
with the command's exit code. With `--json`, pols prints one result containing
stdout, stderr and the exit code after the command completes.

## Usage

```text
pols exec SANDBOX -- COMMAND [ARG...] [flags]
```

## Examples

```sh
pols exec web -- uname -a
pols exec web -- bash -lc 'cd app && npm test'
echo 'print(1)' | pols exec web --stdin -- python3
```

## Flags

```text
    --cwd string             working directory (default: the user's home)
-e, --env stringArray        environment variable for this command: KEY copies it from your environment, KEY=VALUE sets it (repeatable)
    --env-file stringArray   read KEY=VALUE lines from a file (repeatable; --env wins)
-h, --help                   help for exec
    --root                   run as root
-i, --stdin                  send local stdin to the command (up to 768 KiB)
    --timeout int            kill the command after this many seconds (default 600)
```

The [global flags](/reference/cli/#global-flags) work with this command too.
