---
search:
  tags:
    - exec
    - POST
seo:
  description: >-
    With Accept: application/x-ndjson the output is streamed as it is produced,…
    Reference for the POST /v1/sandboxes/{sandbox}/exec endpoint in the pols.so
    API.
sidebar:
  label: Run a command in a running sandbox
  badge: POST
title: Run a command in a running sandbox
type: openapi-operation
---
With `Accept: application/x-ndjson` the output is streamed as it is
produced, one `ExecEvent` JSON object per line, ending with an `exit`
(or `error`) event. Otherwise the call waits and returns an
`ExecResult` with the collected output (capped at 4 MiB per stream;
stream larger output).

A command that runs past `timeout_seconds` is killed: the call
answers 504 `timeout`, or a stream ends with an `error` event with
`timed_out: true`. Closing the connection (aborting the call) kills
the command too. Killing ends the command's whole process group
(background jobs included), not processes that left it, such as
daemons that start their own session.

A `cwd` that does not exist or that the user cannot enter is not an
API error: the command does not run and the call reports exit code
125 with the reason on stderr, like `env -C`. A command that is not
found exits 127.

`POST /v1/sandboxes/{sandbox}/exec`
