Process execution
Execute and manage processes in sandboxes.
Execute and manage processes in your sandboxes with Blaxel SDK. Run shell commands, retrieve process information, and control process execution.
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
.env
file (BL_WORKSPACE
andBL_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)
When developing locally, the recommended method is to just log in to your workspace with Blaxel CLI. This allows you to run Blaxel SDK functions that will automatically connect to your workspace without additional setup. When you deploy on Blaxel, this connection persists automatically.
When running Blaxel SDK from a remote server that is not Blaxel-hosted, we recommend using environment variables as described in the third option above.
Execute command
Execute shell commands using the TypeScript SDK:
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.
You can use either the process name or the process ID to get information about the process:
You can also use the process ID or name to retrieve logs of your processes.
Wait for process completion
You can wait for process completion when executing it:
Notice the timeout
parameter which allows to set a timeout duration on the process.
waitForCompletion
, Blaxel enforces a timeout limit of 100 seconds. Don’t set your timeout longer than this. For longer waiting periods, use the process-watching option described below.You can also wait for a process after it has started:
Set a long completion duration if your process is expected to take longer.
Wait for ports
In some cases, you may want to wait for a port to be opened while running — for example if you are running npm run dev
and want to wait for port 3000 to be open.
Kill process
Kill a process immediately by running:
Process statuses
A process can have either of the following status:
running
completed
failed
killed
stopped
Call a sandbox on a specific port
You can call your sandbox on a specific port by using a URL that follows this format. This is useful when you need to expose specific services or applications running in your sandbox: