Start an Exec
- CLI:
execstreams the command’s stdout and stderr to yours and exits with its exit code. With-i, your stdin is passed to the command; with--detach(-d), the command starts and its exec ID is printed.
Idempotency-Key. The CLI also resumes reading output after a dropped connection; with curl, read the output through the exec attach WebSocket.
Through the REST API, the call returns
201 at once, without waiting for the command or streaming its output. The exec is running, or exited with its exit_code if it already finished.
- If the sandbox can’t confirm the start within a few seconds, the exec comes back
startingand the start completes in the background. A start that can’t be confirmed within 5 minutes endsfailedwith reasonagent_unavailable. - The sandbox must be
running(409 sandbox_not_runningotherwise). - Send an
Idempotency-Key. A retry with the same key returns the same exec instead of running the command twice, and completes a start that is stillstarting.
Statuses
An exec that is
failed with agent_unavailable or cancelled can still move on to running, exited, or terminated if its start did reach the sandbox.
Wait for an Exec
GET /v2/ai/sandboxes/{sandbox_id}/execs/{exec_id}?wait=10 is a long poll: it returns 200 as soon as the exec has ended, or after at most 10 seconds. Call it again until status is exited, failed, or terminated. Without wait, it returns at once. If the sandbox can’t answer, the response carries the last known state.
GET /v2/ai/sandboxes/{sandbox_id}/execs lists a sandbox’s execs, newest first, optionally filtered by repeated status parameters. A status in the list can lag the process by up to about 15 seconds; GET …/execs/{exec_id} asks the sandbox.
Output and Stdin
Exec output isn’t part of the sandbox’s logs. Read it, and write to the exec’s stdin, through the exec attach WebSocket. The CLI’sexec and execs attach commands use it for you. Each exec keeps at least its last 64 MiB of output for replay, within a per-sandbox total of 1/16 of the sandbox’s memory, at most 256 MiB. That retained output counts against the sandbox’s memory.
POST /v2/ai/sandboxes/{sandbox_id}/execs/{exec_id}/stdin/close sends EOF to the exec’s stdin, once the input already accepted has been written. Disconnecting from the attach WebSocket never sends EOF: a process reading stdin keeps waiting until it gets stdin_eof or this call. Closing twice, or closing an exec that ended, changes nothing. The CLI’s equivalent is telnyx-edge sandbox-gpu execs close-stdin.
Send a Signal
signal is one of SIGTERM, SIGKILL (default), SIGINT, SIGHUP, SIGQUIT, SIGUSR1, or SIGUSR2.
- The call is asynchronous: it returns
202with the exec as it is right after. WithSIGKILL, the exec ends shortly after withstatus: exitedandexit_code: 137. - Signalling an exec that already ended changes nothing.
- An exec still
startingcan only be cancelled:SIGKILLensures the command never runs, and it endsfailedwith reasoncancelled. Any other signal fails with409 exec_not_started; retry once the exec isrunning. - With an
Idempotency-Key, a retry replays the first answer. Two overlapping requests with the same key may both deliver the signal.
Activity
Starting, running, and finishing execs, and writing to an exec’s stdin, count as activity for the sandbox’sidle_timeout. See Timeouts.