terminal.open() for programs that require a pseudo-terminal or interactive input. Read terminal output, write input, resize the terminal, and wait for it to exit.
Opening a terminal starts a stopped Devbox automatically. Unlike Namespace Sessions, an SDK terminal is tied to its connection and does not persist for later reattachment.
terminal.open()
Open an interactive shell in the Devbox and control it through a TerminalSession.
Example
Open a terminal, print its output, run a command, and wait for it to exit:API reference
Arguments and options
TerminalOpenOptions
Options used to open the terminal.
Return value
terminal.open() resolves with a TerminalSession.
TerminalSession are documented below.
More examples
Forward local input
Forward local terminal input to a remote shell and keep it open until the user typesexit.
terminal.write()
Send text or bytes to the terminal’s standard input. Strings are written as provided, so include \n when submitting a command.
Example
API reference
Arguments and options
string | Uint8Array
required
Text or bytes to send to the terminal.
write() throws an Error if the terminal is already closed.
terminal.resize()
Change the dimensions of the remote pseudo-terminal.
Example
API reference
Arguments and options
number
required
The new terminal width in columns.
number
required
The new terminal height in rows.
resize() throws an Error if the terminal is already closed.
terminal.close()
Close the terminal locally. Calling close() more than once has no effect.
Example
API reference
Arguments and options
This method has no arguments or options. Closing the terminal causes pendingwait() calls to resolve when the underlying channel closes. A locally closed terminal reports a null exit code and signal.
terminal.onData()
Subscribe to terminal output. Standard output and standard error are delivered through the same listener.
Example
API reference
Arguments and options
(data: Uint8Array) => void
required
Called with each output chunk.
Return value
Returns a function that removes the listener.More examples
Stop listening for output
terminal.onExit()
Subscribe to the terminal’s exit event.
Example
API reference
Arguments and options
(exitCode: number | null, signal: string | null) => void
required
Called when the terminal closes. Either value may be
null when the remote side does not report it.Return value
Returns a function that removes the listener.terminal.onError()
Subscribe to terminal transport errors.
Example
API reference
Arguments and options
(error: Error) => void
required
Called when the terminal transport reports an error.
Return value
Returns a function that removes the listener.terminal.wait()
Wait for the terminal to close. Calling wait() after exit resolves immediately with the recorded result.
Example
API reference
Arguments and options
This method has no arguments or options.Return value
number | null
required
The remote shell’s exit code, or
null when no exit code is available.string | null
required
The signal that ended the remote shell, or
null when no signal is available.Related documentation
Run commands
Run structured commands and shell scripts without an interactive terminal.
Handle errors and timeouts
Cancel operations and handle SDK failures.