Skip to main content
In many situations, you’ll need to operate a sandbox from a frontend client. When doing so, you cannot share the Blaxel credentials needed to access the sandbox. The solution is to use sessions. Sessions are created for a sandbox from a backend server (using Blaxel credentials) and then shared with the frontend client, allowing the browser to connect to the sandbox. From a session, you can:
  • only interact with the sandbox API (i.e. manage the sandbox filesystem, processes and logs).
From a session, you cannot:
  • interact with Blaxel API to create other preview URLs or sessions. These operations must be done server-side.

Basic example

Create a temporary backend session to access a sandbox instance from your client application. Main parameter for this is expiresAt, a Date() corresponding to the expiration date.

Create if expired

This helper function either retrieves an existing session or creates a new one if it expired. You can optionally pass delta (default: 1 hour), the time window in milliseconds before actual expiration when a session should still be recreated.

Example (NextJS)

The following example demonstrates a full implementation of sessions in a backend server and frontend client using NextJS.

Server code (backend)

Client code (frontend)

Last modified on May 14, 2026