> ## Documentation Index
> Fetch the complete documentation index at: https://docs.morphllm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Blaxel Sandboxes

> Apply edits and execute AI code via tool calls inside a secure sandboxed environment on Blaxel.

[Blaxel](https://blaxel.ai) Sandboxes are fast-launching compute runtimes in which coding agents can securely execute code and manage files, with \~25ms cold-starts and automatic hibernation when idle.

You can use Morph’s fast apply model to update files in a sandbox’s filesystem with near-instant response times through agentic tool calls, leveraging the Morph integration within the sandbox’s MCP server.

## Why Blaxel + Morph?

* **Speed**: Blaxel's 25-ms cold-starts rank among the lowest in serverless sandbox environments, which when combined with Morph’s blazing-fast applies makes for a near-instant user experience.
* **Security**: Your code that gets created by Morph should never be accessed by someone else, and microVM-based sandboxes ensure the highest level of isolation
* **Price**: Only pay for real usage and never more: tokens generated and sandbox active runtime

## Quick Setup

* Create a Blaxel account and workspace on [app.blaxel.ai](http://app.blaxel.ai)
* Install [Blaxel's Python or TypeScript SDK](https://docs.blaxel.ai/sdk-reference/introduction) through one of the following methods:

<CodeGroup>
  ```shell TypeScript (pnpm) theme={null}

  pnpm install @blaxel/core

  ```

  ```shell TypeScript (npm) theme={null}

  npm install @blaxel/core

  ```

  ```shell TypeScript (yarn) theme={null}

  yarn add @blaxel/core

  ```

  ```shell TypeScript (bun) theme={null}

  bun add @blaxel/core

  ```

  ```shell Python (pip) theme={null}

  pip install blaxel

  ```

  ```shell Python (uv) theme={null}

  uv pip install blaxel

  ```

  ```shell Python (uv add) theme={null}

  uv init && uv add blaxel

  ```
</CodeGroup>

* Create a [Morph API key](https://docs.morphllm.com/api-reference/introduction#authentication) to connect to your Morph workspace from the sandboxes
* Create your first [Blaxel sandbox](https://docs.blaxel.ai/Sandboxes/Overview) programmatically, making sure to pass the `MORPH_API_KEY` and `MORPH_MODEL` (default = *morph-v3-large*)

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { SandboxInstance } from "@blaxel/core";

  // Create a new sandbox
  const sandbox = await SandboxInstance.create({
    name: "my-sandbox",
    image: "blaxel/prod-base:latest",
    memory: 4096,
    ports: [{ target: 3000, protocol: "HTTP" }]
    envs: [
      { name: "MORPH_API_KEY", value: "YOUR_API_KEY" },
      { name: "MORPH_MODEL", value: process.env.MORPH_MODEL || "morph-v3-large" }
    ]
  });

  // Wait for deployment
  await sandbox.wait();
  ```

  ```python Python theme={null}
  from blaxel.core import SandboxInstance

  # Create a new sandbox
  sandbox = await SandboxInstance.create({
    "name": "my-sandbox",
    "image": "blaxel/prod-base:latest",
    "memory": 4096,
    "ports": [{ "target": 3000 }]
    "envs": [
      { "name": "MORPH_API_KEY", "value": "YOUR_API_KEY" },
      { "name": "MORPH_MODEL", "value": os.getenv("MORPH_MODEL") or "morph-v3-large" }
    ]
  })

  # Wait for deployment
  await sandbox.wait()
  ```
</CodeGroup>

## Use the fast apply

Blaxel sandboxes have an **MCP server** for accessing the file system and processes via tool calls. Morph’s fast apply is accessible exclusively through this [MCP server](https://docs.blaxel.ai/Sandboxes/Overview#mcp-server-for-a-sandbox), via the tool `codegenEditFile`.

Use Blaxel SDK to retrieve this tool and others in any [compatible agent framework](https://docs.blaxel.ai/Frameworks/Overview) (here in AI SDK format for TS, LangGraph for Python) by first installing the SDK adapters:

<CodeGroup>
  ```shell TypeScript (pnpm) theme={null}

  pnpm install @blaxel/vercel

  ```

  ```shell TypeScript (npm) theme={null}

  npm install @blaxel/vercel

  ```

  ```shell TypeScript (yarn) theme={null}

  yarn add @blaxel/vercel

  ```

  ```shell TypeScript (bun) theme={null}

  bun add @blaxel/vercel

  ```
</CodeGroup>

And running the following code to retrieve the fast apply tool as well as others to operate the sandbox. Call the `codegenEditFile` tool to fast-apply a targeted edit to a specified file, with instructions and partial contents.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { blTools } from '@blaxel/vercel';

  // Get tools from sandbox MCP
  const allTools = await blTools([`sandboxes/${sandbox.metadata.name}`]);

  // Filter for specific fast apply tool
  const morphTool = Object.fromEntries(
    Object.entries(allTools).filter(([key]) =>
      key.startsWith('codegenEditFile')
    )
  );

  // You can now pass it as a standard tool in an AI SDK agent to use
  // …
  ```

  ```python Python theme={null}
  from blaxel.langgraph import bl_tools

  # Get tools from sandbox MCP
  all_tools = await bl_tools([f"sandboxes/{sandbox.metadata.name}"])

  # Filter for the fast apply tool
  morph_tool = [tool for tool in all_tools if tool.name.startswith("codegenEditFile")]

  # You can now pass it as a standard tool in a LangGraph agent to use
  # …
  ```
</CodeGroup>
