Execute processes and commands
Set up authentication to Blaxel
Set up authentication to Blaxel
The Blaxel SDK authenticates with your workspace using credentials from these sources, in priority order:
- when running on Blaxel, authentication is handled automatically
- variables in your
.envfile (BL_WORKSPACEandBL_API_KEY, or see this page for other authentication options). - environment variables from your machine
- configuration file created locally when you log in through Blaxel CLI (or deploy on Blaxel)
Execute command
Execute shell commands:waitForCompletion: true / "wait_for_completion": True parameter.
Process execution logs are also visible in the Blaxel Console. Refer to the Logs section of the sandbox detail page, as shown below:

Set the working directory
Set the working directory for subsequent commands:Use process names
When starting a process (running a command), you can specify a process name. This lets you interact with the process—such as retrieving logs or process information—without needing to store the process ID on your end.exitCode parameter of the process execution object returned by the process.exec and process.get methods.
You can also use the process ID or name to retrieve logs of your processes.
Kill process
Kill a process immediately by running:Long-running processes
Wait for process completion
You can wait for process completion when executing it:.logs object which surfaces both stdout and stderr. Also, notice the timeout parameter which allows to set a timeout duration on the process.
You can also wait for a process after it has started:
Wait for ports
In some cases, you may want to wait for a port to be opened while running — for example if you are runningnpm run dev and want to wait for port 3000 to be open.
Auto-restart
Restart process on failure
You can restart a process if it fails, up to a maximum number of restart attempts:Sandbox keep-alive
By default, sandboxes automatically switch to standby after a few seconds of inactivity to save resources. However, it is possible to adjust this behaviour and keep the sandbox running when you launch a process, even if there isn’t an active connection to it. This is typically used to keep a server running in the sandbox environment even when it is not serving requests. To use this feature, you must first:-
build or rebuild your custom sandbox image with a specific version of the sandbox API that supports the keep-alive feature:
-
use a specific development version of the Blaxel TypeScript SDK:
TypeScript
timeout value is not specified, it defaults to 600 seconds. For processes that should run indefinitely until they complete naturally, set the timeout to 0.
You can run multiple processes, and the sandbox will stay active until all of them complete:
TypeScript
Process statuses
A process can have either of the following status:runningcompletedfailedkilledstopped
