Run commands and long tasks
Two ways to run a program on a machine: exec_run waits for it and returns its exit code, and
task_start starts it in a terminal that keeps running after your call or your conversation ends.
Before you start
Both need the exec class in your grant and in the machine’s ceiling. Without it the call returns
denied: tell the owner, do not retry.
Run a command and wait
-
Call
exec_runwithargv(run directly, no shell) orcommand(run as/bin/sh -c):{ "machine": "build-box", "argv": ["cargo", "test", "--quiet"], "cwd": "~/src/app", "timeout_secs": 300 } -
Read the result:
exit_code,stdoutandstderrapart, andtimed_out. A non-zero exit is a normal result, not an error: decide from the code and the output.
Limits:
timeout_secsdefaults to 120, at most 600. On timeout the whole process group is stopped.- Each stream keeps its last 64 KiB; longer output is saved to the files named in
stdout_fileandstderr_file, which you can read withfs_read. - The command starts with a small base environment (
PATH,HOME,USER,SHELL, the locale, the desktop session) plus what you pass inenv. Nothing else from the machine program’s own environment reaches it, so a key set there is not passed on.
Start a long task
For a dev server, a build that takes longer than ten minutes, or anything interactive:
- Call
task_startwithargvorcommand, andcwd. It returns the task id at once. - Read the task’s screen with
task_output{"task": <id>}: the last 200 lines by default,lines: 0for all the machine keeps. Call it again to follow progress; it works whether the task still runs or has ended. - End it with
task_stop: the machine sends SIGTERM to its process group, and SIGKILL after 5 seconds.
Lost the id? Over MCP, tasks_list returns everything running now, by author
(MCP server).
What a task survives, and what it does not:
| Event | The task |
|---|---|
| your call or conversation ends, the page closes, the network drops | keeps running; reconnect and read it |
| the machine is paused | is stopped, with every other task |
| the machine program restarts | is stopped; it is listed as lost |
The machine keeps 1000 lines of output of its last 50 tasks until it restarts.
Check
exec_run returns exit_code: 0 for the command you expected to succeed. For a task,
task_output shows the program’s own output, and tasks_list lists it under your name.
If it fails
busy: the machine already runs 8 calls at once. Wait and retry.paused: the owner paused the machine; stop and tell them.timed_out: the call did not finish in time. For long work use a task instead.