Overview
Named shells are persistent, stateful shell sessions that maintain environment variables and the current working directory (CWD) across commands. This behavior should feel familiar: it’s like using a single shell locally—when you change directories or set environment variables, those changes persist for subsequent commands. Commands executed through the same named shell instance execute sequentially (with automatic queuing), ensuring that environment changes and directory changes from one command are preserved for the next command.Creating a Named Shell
Usedevbox.shell() to create a named shell instance. You can provide a custom name, or omit it to let Runloop generate a unique shell name for you.
Maintaining Working Directory
Named shells preserve the current working directory across commands. This eliminates the need to repeatedly usecd commands.
Maintaining Environment Variables
Named shells also preserve environment variables across commands, making it easy to set up your environment once and reuse it.Sequential Execution
Commands in a named shell execute sequentially - only one command runs at a time. This ensures that state changes from one command are fully applied before the next command starts.Reusing Named Shells
If you use the same shell name again, you’ll reattach to the existing named shell and reuse its state. This is useful when you need to resume work in a shell session.If two different SDK clients use the same shell name on the same devbox, they share a single underlying named shell. This can be powerful, but be careful: commands from different processes will see the same working directory and environment.
Streaming Output
Named shells support streaming output just like regular command execution. You can stream stdout and stderr in real-time.When to Use Named Shells
Use named shells when you need to:- Maintain working directory: Avoid repeatedly using
cdcommands - Preserve environment: Set environment variables once and reuse them
- Run workflows in sequence: Execute ordered commands that build on previous state
- Resume sessions: Reattach to a previous shell session with preserved state
devbox.cmd.exec() directly without a named shell.
For more information about command execution options, see the Execute Commands documentation.
