Skip to content
pols.so docs
Esc
↑↓navigate↵open⌘Jpreview
On this page

Detached processes

Start a command that keeps running after the call that started it ends, read its output again from any point, and send it signals.

A detached process is a command that keeps running in the sandbox when the call that started it ends: when pols exits, your connection drops or your agent’s tool call times out. You can come back to it at any time, read its output again from any point, and stop it.

pols exec web --detach -- bash -lc 'cd app && make release'
# proc_k3f9a0b1c2d4
pols processes ls web
pols processes logs -f web proc_k3f9a0b1c2d4   # follow it; exits with its exit code
pols processes kill web proc_k3f9a0b1c2d4      # TERM by default

Starting one

pols exec --detach (-d) starts the command and prints the process’s ID (proc_...) at once. Over the API, it is an exec with "detach": true (POST /v1/sandboxes/{sandbox}/exec), which answers 202 with the process instead of waiting for the command.

It takes the same options as any exec: --user, --root, --cwd, --env, --env-file and --stdin. Unlike a plain exec, it has no time limit unless you set one with --timeout (timeout_seconds); a process killed by its time limit exits with 137. Its environment and stdin travel to the sandbox on the start’s own input, never on a command line or in a file other users could read. It runs in a session of its own with its stdout and stderr combined into one output. There is no terminal: for interactive programs, use SSH.

A detached exec cannot also stream its output (Accept: application/x-ndjson); read the output as shown below.

Reading its output

The sandbox keeps the last 1 MiB of each process’s output. pols processes logs SANDBOX PROCESS prints it from --offset, a byte offset into everything the process wrote; -f keeps printing until the process has ended and then exits with its exit code. You can stop pols and run it again at any time.

Over the API, GET /v1/sandboxes/{sandbox}/processes/{process}/output?offset= returns the process, the output from offset as data (at most limit bytes, 1 MiB by default), and next_offset. To follow a process, read again from next_offset until it has ended and data is empty. When output between the offset you asked for and the one returned is no longer kept, truncated is true.

Listing and signalling

pols processes ls SANDBOX (GET /v1/sandboxes/{sandbox}/processes) lists the sandbox’s detached processes, oldest first, with their command, user, status (running or exited) and, once they have ended, exit_code: 128 plus the signal number for one killed by a signal.

pols processes kill SANDBOX PROCESS (POST .../processes/{process}/signal) sends TERM, or with --signal one of KILL, INT, HUP, QUIT, USR1, USR2, STOP and CONT. The signal goes to the process’s session: the command and what it started, unless those started a session of their own.

How long they last

  • A detached process runs on while the sandbox runs. Standby freezes it with the sandbox, and it goes on when the sandbox wakes.
  • Stopping the sandbox ends it, and the sandbox forgets it when it boots again. For services that should come back after a stop, use a systemd unit or a Docker restart policy; see Long-running tasks.
  • A sandbox keeps at most 32 detached processes; a new start forgets the ones that ended longest ago.
  • The output is kept in the sandbox’s memory, not on its disk.

Each start is recorded in the sandbox’s timeline like an exec, and its exit once pols sees it, on the next list or output read. A key limited to one Linux user sees, reads and signals only that user’s processes.

From agents and code

The MCP server has process_start, process_list, process_output (at most 512 KiB a call) and process_signal. An agent whose tool calls time out can start a long build with process_start and check on it with process_output instead of holding one call open.

The TypeScript and Python clients have processes.start, .list, .output and .signal:

import time

proc = pols.processes.start("web", ["bash", "-lc", "make build"])
offset = 0
while True:
    out = pols.processes.output("web", proc["id"], offset=offset)
    print(out["data"], end="")
    offset = out["next_offset"]
    if not out["data"]:
        if out["process"]["status"] == "exited":
            break
        time.sleep(1)