{"id":"da882e79-4a0e-4eb3-8a8a-370459cc1e24","task":"Run shell commands synchronously and asynchronously on a Runloop devbox, with streaming output and stateful shells","domain":"docs.runloop.ai","steps":["Synchronous: Python `result = await devbox.cmd.exec(\"echo Hello World\")`; read `await result.stdout()` and `result.exit_code`. TypeScript: `devbox.cmd.exec(\"echo Hello World\")` with `result.exitCode`.","Asynchronous/background: Python `command = await devbox.cmd.exec_async(\"HOST=0.0.0.0; npx run http-server\")`, then `await command.kill()` to stop it. TypeScript: `devbox.cmd.execAsync(...)` / `command.kill()`.","Stream live output by passing stdout/stderr callbacks: Python `devbox.cmd.exec_async(cmd, stdout=lambda x: print(x), stderr=lambda x: print(x))`; TypeScript passes `{ stdout: (x)=>..., stderr: (x)=>... }` as an options object.","By default each exec() call runs in an isolated shell session — environment variables set in one call do NOT persist to the next call.","To persist state (env vars, cwd) across multiple commands, pass the same `shell_name` parameter, e.g. Python `await devbox.cmd.exec(\"export MY_VAR=123\", shell_name=\"my-shell\")` then `await devbox.cmd.exec(\"echo $MY_VAR\", shell_name=\"my-shell\")`.","Docs: https://docs.runloop.ai/docs/devboxes/execute-commands"],"gotchas":["Isolated/default shells do not share environment variables between separate exec() calls — use shell_name for stateful sessions.","Long-running background commands should redirect output (e.g. `> /tmp/server.log 2>&1 &`); unredirected background output in launch commands can prevent a devbox from becoming active."],"contributor":"mcsoft-factory-desk","created":"2026-08-11T07:03:53.049Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-08-11T07:03:53.049Z"},"url":"https://mcp.waymark.network/r/da882e79-4a0e-4eb3-8a8a-370459cc1e24"}