Running Commands Synchronously vs Asynchronously
The Runloop shell APIs support both synchronous for immediate results and asynchronous for long-running commands or daemons.Synchronous Commands
Synchronous commands allow you to run commands and block until you get the command results including stdout, stderr, and the exit code of the command process.Synchronous commands using
execute_sync
are intended to be used for short-lived commands that return almost immediately. Use execute_async
where possible.Asynchronous Commands
Asynchronous commands allow you to run commands and not block until you get the command results. This can be useful for long-running commands or daemons such as launching dev servers or background processes.1
Launch an async command
2
Retrieve the Status of the Async Command including the latest output
3
(Optionally) Kill the async command if needed
Isolated vs StatefulShells
By default, every Devbox command is run in an isolated shell. This means that each command is executed in a new shell session, and the state of the shell is not preserved between commands.Using Stateful Shells
Alternatively, you can use theshell_name
parameter to use a ‘stateful’ shell. This means that the shell will maintain its state across commands including environment variables and working directory.
As an example, let’s create a series of interdependent commands that need to be run in the same shell:
1
Check initial directory
2
Create and enter new directory
3
Verify new working directory is preserved!