Run a command inside a unit
Code Mode: praxis.devops.units.exec
HTTP: POST /devops/v1/units/{id}:exec
Run one command inside the unit’s own machine, and answer what it printed: exitCode, stdout and stderr, verbatim (the sandbox already caps their length). This is the door for a caller that holds no reach of the machine on its own — an agent whose credential opens development units — and it goes through the unit, the way gh codespace ssh goes through the codespace rather than the VM underneath. The command’s environment carries the caller’s signature — GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL are the caller’s principal id and its noreply address — so a commit made here is signed by whoever ran it, and a checkout that has no user.email of its own is configured with the change’s initiator when the unit is created. cwd defaults to the unit’s repository directory. timeoutMs defaults to 120000 milliseconds and may not exceed 600000, and that 600000 ceiling is fixed: a task that needs longer than 240 seconds is not run by raising it — start it in the background and poll for its result, because a foreground call that long outlives the caller’s own patience, and when the caller disconnects the command used to keep running on the machine with nobody collecting it (the reclaimer that ends that is #4404). When a command is stopped at its budget the answer is exitCode 124 with whatever it had already printed in stdout and stderr, so a stopped command shows its output instead of an empty result. A non-zero exit code is a result, not an error: it comes back in exitCode and is recorded on the unit’s transitions as EXIT_<code> with the first line of stderr. The unit must be available with a machine, or the call answers 409 UNIT_INVALID_STATE — start it first; a unit of another organization answers 404 UNIT_NOT_FOUND, exactly as an unknown id does. The machine holds no git credential, so a commit made here still reaches the remote through devops.units.push; a command that fails to run at all answers 500 EXECUTION_FAILED and the machine’s own words are in the unit’s transitions.
Signature
praxis.devops.units.exec(args:{path:{/** e.g. "wsu_01JQ8Z3M9K4V7B2N6C5X0YTRHW" */ id:string};body:{/** The command line, run by the machine's shell. e.g. "git status --porcelain=v2" */ cmd:string;/** Directory to run in, which must exist on the machine. e.g. "/home/user/workspace/repo" */ cwd?:string;/** How long the command may run, in milliseconds; defaults to 120000 and values above 600000 are refused with 400, and that ceiling does not rise — a task longer t e.g. 120000 */ timeoutMs?:number}}):Promise<{/** The command's exit status as the machine reported it. e.g. 0 */ exitCode:number;/** Everything the command wrote to standard output, verbatim and capped by the sandbox. */ stdout:string;/** Everything the command wrote to standard error, verbatim and capped by the sandbox. */ stderr:string}>;Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| id | path | string | yes | The unit identifier returned by the unit create answer or a unit list, such as wsu_…; not the id of the change it was opened for. |
Request body
| Required | Content types | Description |
|---|---|---|
| yes | application/json |
Responses
| Status | Content types | Description |
|---|---|---|
| 200 | application/json | What the command printed: exitCode, stdout and stderr, verbatim. A non-zero exitCode is a result, not an error. |
| 400 | application/json | INVALID_PARAMS or INVALID_ARGUMENT means a field, query value or identifier violates the documented format or range — an unknown enum value, a pageSize outside 1..100, an unsupported filter or orderBy field, or an id with the wrong prefix. Correct the named input; nothing was read or written. |
| 401 | application/json | The API key is missing or invalid; send a valid Praxis API key in the Authorization header before retrying. |
| 403 | application/json | The credential carries no organization, or that organization cannot reach this project; use a key belonging to the project’s organization. No cross-organization read is possible. |
| 404 | application/json | UNIT_NOT_FOUND means no unit with that id is visible to this organization — a unit belonging to another organization answers the same way, so its existence is not revealed; list the project’s units and use an id from that answer. |
| 409 | application/json | UNIT_INVALID_STATE means the unit is not in a phase where this verb applies — starting one that is already available, for example, or acting while another transition is still in flight; read the unit to see its phase, and retry once it has settled. Nothing changed. |
| 500 | application/json | INTERNAL means the service could not complete the request; retry once, and if it repeats report the request id. A read is safe to repeat; a write that failed this way should be re-read before it is sent again. |