box.exec.command resolves once a command has finished. A live session resolves as soon as the command starts, and hands you a handle to the running process.
That lets you do things a one-shot command cannot: write to stdin while the process runs, drive an interactive program through a real terminal, stream output as it is produced, and signal the process tree.
Live sessions are a Node.js API in the JavaScript SDK. Authentication travels in a request header, and browsers cannot set headers on a WebSocket handshake.
API
Start a session
Passargv to run a program directly with no shell involved, which is the safest option when any part of the command comes from user input.
Output arrives through callbacks as the process produces it. stdout and stderr stay separate.
wait() blocks until the process exits and returns its exit code. In Python you can pass a timeout in seconds to bound the wait, and it raises TimeoutError if that elapses. The JavaScript wait() takes no timeout, so cap it with your own timer if you need one.
Use cmd instead of argv when you want a shell, for pipes, globs, or &&. It runs through bash -lc.
Write to stdin
Send input to the running process. Close stdin when you are done so a command that reads to end of input can finish.Run interactive programs
Settty to allocate a real terminal. Programs that behave differently when piped, such as REPLs, top, or anything drawing a terminal UI, then work as they do in a real shell. Give the terminal a size with rows and cols, and change it later with resize.
With a TTY, stderr is merged into stdout, the same as in a terminal.
Set the directory and environment
cwd places the process, resolving against the box’s current directory. env entries are KEY=VALUE strings overlaid on the box environment.
A few environment variables are reserved by the runtime and are dropped rather than applied, so a session cannot use them to alter how the box itself runs.
Stop a session
terminate asks the server for a graceful stop: SIGTERM now, then SIGKILL after the grace period if the process is still running.
Only the first
terminate starts the sequence. Later calls are ignored, so the grace period cannot be changed once it is running. Use kill("KILL") to stop the process immediately instead.kill sends a single signal to the whole process tree, so background children started by the command are signalled too. It defaults to TERM, and accepts TERM, KILL, INT, HUP, TSTP, QUIT, USR1, and USR2.
The session owns the process
A session is a live connection, and the process belongs to it. Closing the handle, losing the network link, or exiting your program all stop the command rather than leaving it running in the box. Always stop the session on your way out, including when your code raises. In Python the handle is a context manager. In JavaScript, close it in afinally block.