Prerequisites
Before starting, ensure you have:- a Python or TypeScript development environment;
- a Blaxel account and API key. If not, sign up for a Blaxel account and create a Blaxel API key;
- a Claude account with an active subscription or an Anthropic Console account with usage-based billing, required by Claude Code. If not, sign up for an Anthropic account and obtain a subscription or API credits as required;
If you wish to use an Anthropic API key instead of logging in to your Claude or Anthropic Console account, you can still follow this tutorial but you will need to perform alternative steps for API key recognition when starting Claude Code.
Install the Blaxel CLI and SDK
-
Download and install the Blaxel CLI and log in to your Blaxel account:
-
In a new directory, install the Blaxel SDK (Python and TypeScript are both supported):
Create sandboxes
-
In the host environment, define the following variable:
-
Create a script named
main.py(Python) orindex.ts(TypeScript) in the same directory.This script creates two Blaxel sandboxes:claude-sandboxusing Blaxel’s Node.js base imagenextjs-sandboxusing Blaxel’s Next.js base image
- adds the Blaxel API key to
claude-sandboxas an environment variable namedBLAXEL_API_KEY.
- starts the Next.js dev server in
nextjs-sandboxon port 3000; - creates a preview URL for the Next.js service running in
nextjs-sandboxon port 3000; - creates an access token for the preview URL, valid for 24 hours;
- returns the preview URL.
-
Run the script to create the sandboxes and preview URL:
Once complete, the script displays the generated preview URL for the Next.js application (for example,
https://b186....preview.bl.run?bl_preview_token=cbba622560db78e...) and the MCP server URL (for example,https://sbx-nextjs-sandbox....bl.run/mcp) for the Next.js sandbox. Note these values, as you will require them in subsequent steps.
Install and configure Claude Code
-
Connect to the Claude Code sandbox terminal:
-
Execute the following commands to install Claude Code in the sandbox and include it in the system PATH:
For detailed installation instructions, refer to the Claude Code documentation.
-
Add the application sandbox’s MCP server URL (obtained from the sandbox creation script in the previous section) to Claude Code:
-
Confirm that Claude Code is able to connect to the application sandbox’s MCP server. Run the following command and confirm that you see output like
sandbox: .... connected:
Test Claude Code
Start Claude Code in the sandbox:If you wish to use an Anthropic API key instead of logging in to your Claude or Anthropic Console account, refer to the alternative steps for API key recognition when starting Claude Code.
