This tutorial explains how to run an Astro application inside a Blaxel sandbox and expose it securely using sandbox preview URLs.
Prerequisites
Before starting, ensure you have:
- Blaxel CLI installed and authenticated (
bl login)
- Node.js 18+ installed
@blaxel/core package installed in your project (npm install @blaxel/core)
Architecture Overview
Running Astro inside a Blaxel sandbox requires a few adjustments:
- Configuring
astro.config.mjs with host: process.env.HOST and allowedHosts: true
- Exposing the Astro dev server via a Blaxel preview URL
Create a base sandbox image
Dockerfile
astro.config.mjs
Create an astro.config.mjs file that allows external connections:
entrypoint.sh
Create an entrypoint script that starts the sandbox API and the dev server:
blaxel.toml
Create a blaxel.toml file in the same directory as your Dockerfile:
Deploy the sandbox image
Deploy the image by running:
Create or reuse a sandbox
Create a sandbox from the base image:
Astro dev servers work well with permissive CORS headers when accessed through a preview URL:
Alternatively, you can use custom domains to expose previews on your own domain.
Create the preview URL
Astro runs on port 4321, so we expose that port via a preview URL:
Generate a preview token
To securely access the preview, a token is required:
Start the dev server
If not using the entrypoint script, you can start the dev server programmatically:
Stream logs
To monitor the Astro dev server output in real-time:
Access the Astro application
Once everything is running, the Astro application will be available at https://<PREVIEW-URL>?bl_preview_token=<TOKEN>.
Complete example
Here is a full example combining all the steps:
Last modified on August 10, 2026