sandbox_procs
Lists, waits for or stops the commands started with sandbox_exec and background: true, and fetches or waits for a foreground command by its execId. Use it instead of pkill -f or pgrep -f, whose pattern matches every process whose command line holds it, other jobs included.
| Input | Output |
|---|---|
id, action (list, the default, wait or stop), bgId (a background bgId or a foreground execId; required for wait and stop; with list, just that command), all (list only), tailBytes (1 to 16384), timeoutSec (wait only: default 600, at most 600), until (wait only: exit, the default, or ready), readyPort and readyLog (wait only) |
list: procs[{bgId, running, note, cmd, startedAt, logPath, mine, cpu, exitCode, signal, endReason, finishedAt, readyWhen, ready, readyAt, logTail}] and foreground[…], plus finished and a hint when finished commands were left out; one command (bgId) also has steps, and a finished foreground one result; wait: proc and stillRunning (and ready when waiting for readiness); stop: proc and stopped |
Every command started with sandbox_exec and background: true has a bgId and writes its output to its logPath, /work/.sbx/logs/<bgId>.log. sandbox_procs looks after those commands:
sandbox_procs { "id": "<id>" }
sandbox_procs { "id": "<id>", "action": "list", "bgId": "<bgId>" }
sandbox_procs { "id": "<id>", "action": "wait", "bgId": "<bgId>", "timeoutSec": 300 }
sandbox_procs { "id": "<id>", "action": "stop", "bgId": "<bgId>" }
list(also what a call withoutactiondoes) returns{ "procs": [...] }: the background commands still running, oldest first, each withbgId,running,note(as given tosandbox_exec),cmd(its first 120 characters, secret values masked),startedAt,logPath,cpu(the %CPU of all its processes added up; 100 is one core) andmine(whether this conversation started it).foregroundlists the foreground commands running right now, from every conversation using the box, the same way, with theirexecIdasbgId: on a box several conversations share,cpuandmineshow whose work is using the machine. When finished commands were left out,finishedsays how many andhinthow to see them.all: truelists finished ones too, each with itsexitCode(a running command has none).bgIdreturns just that command, running or not, withlogTail, the end of its log.logTailis left out of a plainlist.listwithbgId,waitandstopreturn the last 4096 bytes of the log;tailBytes(1 to 16384) sets how many, also for a plainlist. Secret values in it come back as****(sandbox_exec); the log file itself is not changed.waitblocks until that command ends, or untiltimeoutSecruns out (default 600, at most 600), and returns{ "proc": {...}, "stillRunning": false }, theprocwith itsexitCode. When the time runs out first, it returnsstillRunning: truerather than an error: call it again. Use it for a long build or test run started in the background, instead of polling withsleepinsandbox_exec.until: "ready"returns as soon as the command is ready instead: itsreadyPortaccepts connections or a line of its log matchesreadyLog(both given tosandbox_exec), withready: trueandreadyAt. PassingreadyPortorreadyLogtowaitsets (or replaces) that condition for a command started without one, and impliesuntil: "ready"; the log is searched from its start, so a line printed before the call counts. If the command ends before it is ready,waitreturns it finished withready: false.- A foreground command's
execIdworks asbgId: while it runs,listwith it andwaitshow it withforeground: trueand its output so far aslogTail; once it ends,proc.resultholds what itssandbox_execreturned (stdout,stderr,exitCode,truncated,durationMs,timedOut, andoutputPathwhen the output was cut). Use it when that call was cut off. The last 200 foreground results are kept. steps(one command only) lists whatpsbx-steprecorded in it: each step'sname,exitCode,msandstartedAt, withrunning: truefor the one still going (seesandbox_exec).- A command ended by a signal has
signal, andendReasonsays what sent it:stopped by sandbox_procs stop, the out-of-memory killer (the box ran out of memory), or another process. stopends the command's whole process group:SIGTERM, thenSIGKILLafter 5 seconds if anything is still there. What the command started goes with it, so a server started throughnpxornpm runstops too and its port is freed. It returns{ "proc": {...}, "stopped": true }, withexitCode-1 for a command it stopped. On a command that had already ended, it returns that command's state as it was.- Stop background commands this way, not with
pkill -forpgrep -finsandbox_exec. Commands run from a script file, so the pattern no longer matches the shell running your ownsandbox_exec, but it matches every other process whose command line holds it, other background jobs included.pkill -x <name>matches only the exact process name, for a process you did not start in the background.kill <pid>signals only that one process, and the processes it started (the server under annpx, say) can keep running.stopends the whole group. - Background commands are recorded in
/work/.sbx/procs, so they survive a restart of boxd, the box's agent (an update, a crash, being killed for memory): still-running ones are listed and stopped as before; one that ended while boxd was down hasexitCode-1 and anendReasonsaying its real exit code is unknown. Boxes started from an image older than this lose that record when boxd restarts and answerbgId not found. - Errors: a
bgIdthe box does not know givesbox <id>: bgId not found: …with the likely reason;waitorstopwithoutbgIdgivesbgId is required: list them first with action list; any otheractiongivesaction must be list, stop or wait. - Each call counts as use of the box, like other tools, so waiting for a long job with
waitkeeps the box from being frozen for being idle; on a frozen box it wakes it first (Box states). Background commands carry on across a freeze and thaw, and keep the box awake for at most 1 hour after its last use. A process started with&inside a foregroundsandbox_execis not one of them: this tool does not list or stop it, and the call that started it reports it withleftoverChildren: true(sandbox_exec).
Every tool and topic is listed in the tool reference.