Prerequisites
- Blaxel CLI installed and authenticated with
bl login - Node.js 18 or later
@blaxel/coreinstalled in your project withnpm 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
3000, then expose it through a Blaxel preview URL.
2. Build the sandbox image
Create aDockerfile:
entrypoint.sh script that starts the sandbox API and development server:
3. Configure Next.js
Createnext.config.ts:
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
Createblaxel.toml in the same directory as your Dockerfile:
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:7. Create the preview and token
Next.js runs on port3000. Create a private preview for that port:
8. Start and monitor the development server
If you do not use the entrypoint script, start the development server programmatically: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
@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 insrc/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.