Execute and manage processes in your sandboxes with Blaxel SDK. Run shell commands, retrieve process information, and control process execution.
Complete code examples demonstrating all operations are available on Blaxel’s GitHub: in TypeScript and in Python.

Execute processes and commands

Execute command

Execute shell commands using the TypeScript SDK:
import { SandboxInstance } from "@blaxel/core";

const sandbox = await SandboxInstance.get("my-sandbox");

// Execute command
const process = await sandbox.process.exec({
  command: "echo 'Hello, World!'"
});
Logs for a process are available in the process execution object if the process is started with the waitForCompletion: true / "wait_for_completion": True parameter.

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.
const process = await sandbox.process.exec({
  name: "hello-process",
  command: "echo 'Hello, World!'"
});
const processInfo = await sandbox.process.get("hello-process");
You can use either the process name or the process ID to get information about the process:
const completedProcess = await sandbox.process.get("hello-process");
if (completedProcess.status === "completed") {
  // ...
}
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:
const process = await sandbox.process.exec({
  name: "build-process",
  command: "npm run build",
  waitForCompletion: true,
  timeout: 60000 // 60 seconds
});
When waiting for completion, the process execution object will contain a .logs object which surfaces both stdout and stderr. Also, notice the timeout parameter which allows to set a timeout duration on the process.
When using 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:
await sandbox.process.exec({
  name: "long-task",
  command: "sleep 10"
});

// Wait for completion (max 10 minutes, check every 5 seconds)
await sandbox.process.wait("long-task", {
  maxWait: 600000,
  interval: 5000
});
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.
const process = await sandbox.process.exec({
  name: "dev-server",
  command: "npm run dev",
  waitForPorts: [3000]
});

Kill process

Kill a process immediately by running:
await sandbox.process.kill("test")

Process statuses

A process can have either of the following status:
  • running
  • completed
  • failed
  • killed
  • stopped