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 and BL_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 second option above.
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.
const process =await sandbox.process.exec({ name:"test", command:"echo 'Hello world'",})
You can use either the process name or the process ID to get information about the process:
awaitnewPromise((resolve)=>setTimeout(resolve,10));const completedProcess =await sandbox.process.get("test");if(completedProcess.status !=="completed"){thrownewError("Process did not complete");
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: