Skip to main content
Mastra is an open source TypeScript framework for building agentic applications. It includes built-in support for Blaxel sandboxes, making it possible to create agents that are backed by remote execution environments (sandboxes) in the cloud. This tutorial explores how you can use Mastra with Blaxel.

Prerequisites

The Mastra framework is provider-agnostic and can be used with multiple LLM providers. This tutorial uses Anthropic models, but you can also read about using other models.

1. Install required dependencies

In your Mastra project directory, initialize a new project and add the Mastra and Blaxel packages, tsx to run the TypeScript examples, and Node.js types:
More information on Mastra installation is available in the Mastra documentation.

2. Configure the environment

Add your LLM API key, Blaxel API key, Blaxel workspace name and Blaxel deployment region as environment variables:

3. Build a simple agent

In your project directory, create a file named index.ts with the following code.
TypeScript
This creates a simple sandbox-backed agent on Blaxel with the Mastra framework. Instructions that you send the agent will be executed in a uniquely named sandbox that is dynamically created and managed in your workspace on Blaxel’s infrastructure. Run the agent:
It will create and deploy a Blaxel sandbox using the blaxel/base-image image, then investigate the sandbox and install all the tools required for Go development. Once done, it will return a report of its work and automatically delete the sandbox. Here’s a partial example of the output:

4. Build a streaming coding agent

One of the most popular uses for agents is to generate code. Sandboxes provide isolated execution environments, allowing agents to securely run generated code with no risk of escaping. Update index.ts to build a simple coding agent that accepts tasks from the command line and streams its responses as it works:
TypeScript
This creates a coding agent that accepts requests from the command-line. The coding agent’s uniquely named sandbox is generated from Blaxel’s blaxel/py-app image, which contains a complete Python development environment. Test the agent:
The agent will start working on the task in a sandbox, streaming its responses as it works. Here’s a partial example of the output:
That’s it! You’re ready to start building and deploying Blaxel sandbox-backed agents with Mastra.

Resources

Want more info on developing and deploying agents on Blaxel? Check out the following resources:

Deploy your agent code to Blaxel

Complete tutorial for deploying AI agents to Blaxel.

Manage environment variables

Complete tutorial for managing variables and secrets when deploying to Blaxel.

Mastra documentation

Official Mastra documentation.
Last modified on May 20, 2026