Prerequisites
- A Blaxel account. If not, sign up for a Blaxel account.
- A Blaxel workspace and API key. Learn about Blaxel workspaces and how to obtain a Blaxel API key.
- An API key for a supported LLM provider.
- A Node.js development environment
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:
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 namedindex.ts with the following code.
TypeScript
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. Updateindex.ts to build a simple coding agent that accepts tasks from the command line and streams its responses as it works:
TypeScript
blaxel/py-app image, which contains a complete Python development environment.
Test the agent:
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.
