
Use cases
Some examples of use cases include:- Code review agents that analyze repositories to detect the effects of changes. These agents run fully isolated compute environments for each tenant while keeping them snapshotted in standby between sessions, eliminating the need to clone the repo every time.
- Code generation agents that iterate in their own compute environments, and instantly render live application previews as human users build, step away, and log back in.
- Data analyst agents that execute adhoc data analysis workflows, generating scripts on-the-fly and running them securely against private files or data within an isolated, ZDR-compliant environment.
- Background agents that operate beyond their pre-configured tools. Each agent gets its own “personal computer” where it can autonomously install packages, execute custom scripts, store files, and adapt to new requirements securely. They can parallelize dozens of those personal computers.
Create a sandbox
Using the SDKs
Create a new sandbox using the Blaxel SDK by specifying a name, image to use, optional deployment region, optional labels, and the ports to expose. Note that ports 80 (system), and 443 & 8080 (sandbox API) are reserved by Blaxel.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)
createIfNotExists() (TypeScript) / create_if_not_exists() (Python). This helper function either retrieves an existing sandbox or creates a new one if it doesn’t exist. Blaxel first checks for an existing sandbox with the provided name and either retrieves it or creates a new one using your specified configuration.
Using the CLI and Console
Although less common, it is also possible to create a sandbox via the Blaxel CLI or the Blaxel Console.- CLI
- Console
my-sandbox and then deploys the sandbox on Blaxel.The project directory contains the Blaxel configuration file blaxel.toml, which can be further customized to suit your sandbox deployment requirements, by modifying the base image, memory, environment, etc. Learn more about the blaxel.toml file.Understand sandbox configuration
Images
The list of public images can be found here. To create a sandbox with one of those images, enter
blaxel/{NAME}:latest (e.g. blaxel/nextjs:latest).Memory and filesystem
For maximum performance, Blaxel sandboxes store part of their filesystem in memory. The base of the filesystem (the user-supplied image) is stored as read-only files on host storage using a highly-efficient format called EROFS (Extendable Read-Only File System). On top of the read-only base, a writable layer lives entirely in the sandbox’s RAM usingtmpfs. OverlayFS serves as orchestrator, directing reads to the EROFS base and writes to the in-memory tmpfs filesystem.
Due to this, Blaxel sandboxes reserve, when possible, approximately 50% of the available memory for the tmpfs filesystem. More information on our implementation is available in this blog post.
To avoid out-of-memory errors or if additional storage is required, one option is to add storage using volumes. However, this requires deleting and recreating the sandbox first. In addition, volumes are not as fast as the native in-memory filesystem.
Ports
The following ports are reserved by Blaxel’s system:- 443: This port hosts the main sandbox API and is exposed via HTTPS
- 80: Reserved for system operations
- 8080: Reserved for sandbox API functionality
ports parameter. This allows you to access these ports from outside the sandbox.
Regions
Select the region where you want to deploy your sandbox. If you don’t specify a region, Blaxel will automatically use a default region.Labels
You can also add optional labels for sandboxes. Labels are specified as key-value pairs during sandbox creation.Expiration
Blaxel supports automatic sandbox deletion based on specific conditions.Retrieve an existing sandbox
To reconnect to an existing sandbox, simply provide its name:Delete a sandbox
Delete a sandbox by calling:-
the class-level
delete()method with the sandboxnameas argument, or -
by calling the instance-level
delete()method:
Upgrade a sandbox’s API
Every Blaxel sandbox includes a custom API binary, which is necessary for sandbox functionality like process management and file operations. It is possible to perform an in-place upgrade of this API without needing to recreate or restart the sandbox.This feature is currently in beta and only available for sandboxes built or created with sandbox API v0.2.0 or later (sandboxes created after 2 Feb 2026). For sandboxes built or created earlier than this date/API version, in-place upgrade is not possible; the sandbox must be recreated to obtain the new API.
Connect to a sandbox with an interactive terminal
You can explore the contents of a sandbox with an interactive terminal. You can access this terminal in two ways:-
From the Blaxel Console, by visiting the detail page for your sandbox in your web browser and selecting the Terminal tab:

-
From your local host, by running:

Manage sandbox hibernation
Sandboxes stay active as long as there’s an active connection to them, typically through a WebSocket connection. When a browser tab becomes inactive, the WebSocket should disconnect after some time, but this behavior depends on the specific browser implementation. There are no built-in stop or start functions available in the SDKs to force hibernation. This means you’ll need to rely on other approaches to better control when sandboxes remain active:-
Hide iframe when tab is inactive
Use JavaScript events to detect when a user is not active on the tab:
- Listen for tab visibility events that indicate when the user switches away from your tab
- When the user becomes inactive, hide the iframe containing the sandbox preview
- Show the iframe again when the user returns to the tab
-
Implement auto-disconnect on tab switch
Some browsers (like Chrome) may keep WebSockets alive even when tabs are inactive to improve performance. You can implement an auto-disconnect feature that:
- Detects when users switch tabs
- Automatically disconnects the WebSocket connection
- Reconnects when the user returns
-
Use activity-based timeouts
Set up a timer system in your interface that:
- Monitors user activity (typing, interactions, etc.)
- Hides the preview after a period of inactivity
- Prompts the user to confirm they’re still using the sandbox
sandbox.sessions.create function to manage sessions.
Here is an example of auto disconnect on tab switch with Vite through a plugin:
Sandbox statuses
Blaxel sandboxes go from standby to active in under 25 milliseconds, and scale back down to standby after a few seconds of inactivity, maintaining their previous state after scaling down.- In STANDBY mode: You are not charged for CPU/memory while a sandbox is in standby mode. However, you are charged for the storage of the snapshot and/or the volumes.
- In ACTIVE mode: You are charged for CPU/memory and storage while a sandbox is in active mode. Sandboxes automatically return to standby mode after 1 second of inactivity.
UPLOADING: A new sandbox version has just been uploaded; the build has not started yet.BUILDING: A new sandbox version has been uploaded and the build is in progress.DEPLOYING: The sandbox deployment is in progress.DEPLOYED: The sandbox is ready to use.FAILED: An error occurred during the build or deployment of the sandbox.TERMINATED: A TTL was set for the sandbox; it has been deleted and will be removed from the API/UI soon.DELETING: A deletion request has been triggered and the deletion is in progress.
UPLOADING/BUILDING statuses only appear when using bl deploy from a sandbox template folder.Expiration policies
Automatically delete sandboxes based on specific conditions.
MCP server
Interact with a sandbox through its MCP server.
Processes and commands
Execute and manage processes in sandboxes.
File system operations
Manage directories and files in sandboxes.
Tools for AI codegen
Manage codebases with tools specifically designed for code generation.
Log streaming
Access logs generated in a sandbox.
Ports
Expose and connect to ports of a sandbox.
Preview in real-time
Render code in real-time via a direct preview URL.
Sessions
Manage temporary sessions to connect to sandboxes from a frontend client.
Volumes
Attach volumes to sandboxes to persist files.
Templates
Create custom sandbox templates.
Example: Connect Claude Code to a Blaxel Sandbox
Connect a Claude Agent SDK agent to a Blaxel sandbox and operate it using its MCP server.
See more tutorials and examples
Read tutorials for running applications built with popular frameworks like Astro, Expo and Next.js on Blaxel.
Sandbox API
Access the your sandbox with an HTTP REST API.

