commands.run
Run a shell command in the machine.
The result (
CommandResult) is { stdout, stderr, exitCode, timedOut, truncated, error? }. Without
callbacks, the result arrives in one response with each output stream cut at 1 MiB, and truncated says
so.
Commands are never retried.
A non-zero exit throws CommandExitError, which carries the same fields. A command that runs past
timeoutMs throws it with timedOut: true and exit code 124.
Streaming output
WithonStdout or onStderr the output is streamed: each callback is called with every chunk as the
command writes it. A returned promise is awaited before the next chunk. run still resolves, or throws
CommandExitError, with the whole stdout and stderr once the command ends. Streamed output is not
capped, so truncated is false. A callback that throws ends the command, and run rejects with that
error.
Background commands
Withbackground: true, run starts the command detached, as a job in its own session, and returns a
CommandHandle at once. It is not limited to 10 minutes.
pid: the shell, which leads the process group.jobId: the job’s ID. The CLI sees the same job:instabox jobs ls,instabox jobs logs <id-or-name> <jobId> -f,instabox jobs wait.kill(): sends SIGTERM to everything the command started. Returnsfalseif all of it had exited.wait({ onStdout?, timeoutMs?, signal? }): follows the job’s log, callingonStdoutwith each chunk from the start, and resolves with{ stdout, stderr: '', exitCode, timedOut: false, truncated: false }once it ends. A background command’s stdout and stderr go to one log (~/.instabox/jobs/<jobId>/out), sostdoutholds both. A non-zero exit throwsCommandExitError. A job that ended without an exit code (the machine restarted) throwsjob_lost.timeoutMsgives up withInstaboxTimeoutError(job_wait_timeout), andsignalstops waiting (aborted). The job keeps running in both cases.
run does not take onStdout, onStderr or stdin with background: true: it throws InstaboxError
with code bad_request. Pass onStdout to wait() instead. Background commands need bash, util-linux
setsid and GNU coreutils in the machine. Without them, run throws background_unsupported, naming
what is missing.
commands.exec
Run a command and return itsCommandResult without throwing on a non-zero exit.
cwd, envs, timeoutMs and stdin. exec is marked internal. run is the supported call.