Skip to main content
This guide explains how to run a Next.js application inside a Blaxel Sandbox and expose it securely using Blaxel previews.

Prerequisites

  • Blaxel CLI installed and authenticated with bl login
  • Node.js 18 or later
  • @blaxel/core installed in your project with npm install @blaxel/core

1. Understand the architecture

Running Next.js inside a Blaxel Sandbox requires minimal adjustments compared to local development:
  • Next.js binds to all interfaces by default in development mode
  • Blaxel exposes services through preview URLs
  • The preview URL handles routing and authentication
Run the Next.js development server on port 3000, then expose it through a Blaxel preview URL.

2. Build the sandbox image

Create a Dockerfile:
Create an entrypoint.sh script that starts the sandbox API and development server:

3. Configure Next.js

Create next.config.ts:
The allowedDevOrigins setting lets the development server accept requests from Blaxel preview origins. If your Blaxel workspace uses a custom domain, add it to the array:

4. Configure and deploy the image

Create blaxel.toml in the same directory as your Dockerfile:
Deploy the image:
For more information about reusable images, see sandbox images.

5. Create or reuse a sandbox

6. Configure preview response headers

Next.js development servers work well with permissive CORS headers when accessed through a preview URL:
Alternatively, use custom domains to expose previews on your own domain.

7. Create the preview and token

Next.js runs on port 3000. Create a private preview for that port:
Generate a token that expires after one day:

8. Start and monitor the development server

If you do not use the entrypoint script, start the development server programmatically:
Stream its logs:

9. Access the Next.js application

Once the server is running, open:

10. Run the complete example

The following example creates the sandbox and preview, starts the server when needed, prints the access URL, and streams logs:

11. Use Next.js features

Turbopack

The template uses Turbopack, Next.js’s Rust-based bundler. It provides:
  • Faster cold starts
  • Instant hot module replacement
  • Optimized incremental compilation
The @next/swc-linux-x64-musl package is preinstalled for Alpine Linux performance.

App Router

The template configures the App Router with the /app directory structure. It provides:
  • Server Components by default
  • Nested layouts
  • Loading and error states
  • Server Actions

TypeScript, Tailwind CSS, and ESLint

The template enables TypeScript with strict type checking. Tailwind CSS is preconfigured in src/app/globals.css, and ESLint uses the recommended Next.js rules. This setup runs Next.js fully inside a Blaxel Sandbox, securely exposes the development server, supports Fast Refresh, and provides a fast environment for previews, internal demos, and AI-powered coding workflows.

Resources

Real-time previews

Configure public and private preview URLs for sandbox services.

Sandbox images

Build and manage reusable Blaxel Sandbox images.
Last modified on October 5, 2026