Execute processes and commands
Learn more about authentication on Blaxel
Learn more about authentication on Blaxel
The Blaxel SDK requires two environment variables to authenticate:
You can create an API key from the Blaxel console. Your workspace name is visible in the URL when you log in to the console (e.g. When developing locally, you can also log in to your workspace with Blaxel CLI (as shown above). This allows you to run Blaxel SDK functions that will automatically connect to your workspace without additional setup. When you deploy on Blaxel, authentication is handled automatically — no environment variables needed.
| Variable | Description |
|---|---|
BL_WORKSPACE | Your Blaxel workspace name |
BL_API_KEY | Your Blaxel API key |
app.blaxel.ai/{workspace}).Set them as environment variables or add them to a .env file at the root of your project: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 field with the combined stdout and stderr output as a string. 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. You can include additional keep-alive metadata when launching a new process: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:
Process statuses
A process can have either of the following status:runningcompletedfailedkilledstopped
