Skip to content

Long-running work

sb.run() waits until the command finishes. The default timeout is 120 seconds; the ceiling is 24 hours. Every command runs as a job inside the machine, so a dropped connection does not stop it.

from sistemo import Sandbox
with Sandbox(stack="python") as sb:
r = sb.run("pip install -r requirements.txt && pytest", timeout=3600)
print(r.exit_code, r.stdout)
import { Sandbox } from "@sistemo/sdk";
const sb = await Sandbox.create({ stack: "node" });
try {
const r = await sb.run("npm ci && npm test", 3600);
console.log(r.exitCode, r.stdout);
} finally {
await sb.close();
}

timeout is enforced inside the machine. When it fires the process is killed (exit 124).

A process the script starts in the background keeps running after the command returns, the same as after an SSH session. Once the command has finished, the server stays up until it exits, you stop it, or the machine stops.

sb.run("nohup python3 -m http.server 8000 > /var/log/web.log 2>&1 &")
print(sb.run("curl -s localhost:8000 | head -3").stdout)

The command’s timeout and cancel apply only while the command itself is still running: then they stop it and everything it started, including processes it detached with setsid or &. After the command has finished, neither reaches its background processes. Stop a server yourself when you are done with it:

sb.run("pkill -f 'http.server 8000'")

If you need logs as they happen, or to survive a client crash, use the same job with a handle:

job = sb.start("npm ci && npm run build", timeout=3600, exec_id="build-1")
for chunk in job.stream():
print(chunk, end="")
print(job.wait().exit_code)
# later
job = sb.job("build-1")

REST: POST /v1/machines/{id}/execs (you mint exec_id), then GET status / output, DELETE to cancel. See Exec.

  • Exec
  • Files — run() output is 32 MiB per stream, with truncated