Skip to main content
This tutorial explains how to run Claude Code inside a Blaxel sandbox and have it execute coding tasks on a codebase hosted in a different sandbox.

Prerequisites

Before starting, ensure you have:
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

  1. Download and install the Blaxel CLI and log in to your Blaxel account:
  2. In a new directory, install the Blaxel SDK (Python and TypeScript are both supported):

Create sandboxes

  1. In the host environment, define the following variable:
  2. Create a script named main.py (Python) or index.ts (TypeScript) in the same directory.
    This script creates two Blaxel sandboxes:
    • claude-sandbox using Blaxel’s Claude Code image
    • nextjs-sandbox using Blaxel’s Next.js base image
    In the Claude Code sandbox, it:
    • uses the blaxel/claude-code:latest image, which includes Claude Code and the sandbox API;
    • adds the Blaxel API key to claude-sandbox as an environment variable named BLAXEL_API_KEY.
    In the application sandbox, it:
    • starts the Next.js dev server in nextjs-sandbox on port 3000;
    • creates a preview URL for the Next.js service running in nextjs-sandbox on port 3000;
    • creates an access token for the preview URL, valid for 24 hours;
    • returns the preview URL.
  3. 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.

Configure Claude Code

  1. Connect to the Claude Code sandbox terminal:
  2. Confirm Claude Code is available in the sandbox:
    The blaxel/claude-code:latest image includes Claude Code on PATH.
  3. Add the application sandbox’s MCP server URL (obtained from the sandbox creation script in the previous section) to Claude Code:
  4. 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:
Claude Code is now ready to operate the sandbox using the sandbox’s MCP tools.

Test Claude Code

Start Claude Code in the sandbox:
You will be prompted for authentication, theme selection and permissions.
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.
Once these steps are completed, give Claude Code a coding task referencing the application sandbox, as in the example prompt below:
Claude Code will connect to the application sandbox, inspect the Next.js codebase and make changes as per your request. You may be prompted for permissions to use the sandbox MCP tools during the process. Once complete, visit the application sandbox’s preview URL (obtained from the sandbox creation script in the previous section) to see the result.

Resources

Want more information on building and deploying with Claude on Blaxel? Check out the following resources:

Claude Agent SDK

Build and deploy Claude Agent SDK agents on Blaxel.

Connect to a Blaxel sandbox from Claude Agent SDK

An agent that operates a sandbox using the sandbox’s MCP server and Claude Agent SDK.

Use Claude Agent SDK with MCP code mode on Blaxel

Build an agent that connects to a Blaxel MCP server running in code mode using Claude Agent SDK.

Self-host Claude Managed Agents on Blaxel

Deploy a self-hosted Claude Managed Agents environment on Blaxel.

Deploy your agent code to Blaxel

Complete tutorial for deploying AI agents on Blaxel.
Last modified on July 10, 2026