The OpenAI Agents SDK is an open source, production-grade library for building agentic applications leveraging the Codex harness. One of the most interesting features of this SDK is the ability to create agents that are backed by remote execution environments (sandboxes) in the cloud. This ability allows the harness to get access to its own computer to execute commands, work with files and directories, write code, and perform computations. This tutorial explores how you can deploy your OpenAI Agents SDK projects to Blaxel with minimal code editing (and zero configuration), enabling you to colocate them close to the sandboxes the agents work on.Documentation Index
Fetch the complete documentation index at: https://docs.blaxel.ai/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
- An OpenAI API key. If not, sign up for an OpenAI account and obtain an API key.
- 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.
The OpenAI Agents SDK is provider-agnostic and can be used with both OpenAI and non-OpenAI models. This tutorial uses OpenAI models, but you can also read about integrating other models.
1. Install the Blaxel CLI and log in to Blaxel
The main way to deploy an agent on Blaxel is with the Blaxel CLI. This method is detailed in this tutorial. Alternatively you can connect a GitHub repository - any push to themain branch of the repository will automatically update the deployment on Blaxel - or deploy from a variety of pre-built templates using the Blaxel Console.
Install the Blaxel CLI and log in to Blaxel using this command:
2. Install required dependencies
Create a directory for the project:3. Configure the environment
Add your OpenAI API key, Blaxel API key and Blaxel workspace name to a.env file in the project directory:
4. Build a simple agent
In your project directory, create a file namedmain.py (Python) or index.ts (TypeScript) with the following code:
agent-sandbox that is dynamically created and managed in your workspace on Blaxel’s infrastructure.
The agent’s HTTP service must be bound to the host and port provided by Blaxel. Blaxel automatically injects these values as
HOST and PORT variables into the runtime environment. It is important to read these variables in your code and ensure that the agent’s HTTP service binds to the correct host and port.scripts section of the package.json file. Update your package.json to ensure that start and dev scripts are defined in the scripts section (TypeScript only).
5. Enable telemetry (optional)
Instrumentation happens automatically when workloads run on Blaxel. To enable telemetry:-
Add the required package to your project:
-
Import the package in your code:
6. Test the agent locally
Test the agent by making the endpoint available locally:--hotreload flag monitors and reloads the agent if the source code changes.
Note the host port on which the agent is running.
In another terminal, send the agent a request (update the endpoint URL below with the correct port number for your agent):
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.
7. Deploy the agent on Blaxel
You’re now ready to deploy the agent on Blaxel. When deploying to Blaxel, your workloads are served optimally to dramatically accelerate cold-start and latency while enforcing your deployment policies. For Python, create arequirements.txt file in the project directory with the following dependencies:
Python
package.json already contains all required dependencies from the npm install commands run earlier. No additional file is needed.
Then, deploy the agent by running the following command:
https://run.blaxel.ai/WORKSPACE/agents/AGENT.
8. Test the agent on Blaxel
By default, agents deployed on Blaxel are not public. All agent requests must be authenticated via a bearer token. Requests can be made either via the Blaxel API or the Blaxel CLI. Test the deployed agent by sending an authenticated request to its global endpoint (update the endpoint URL below with the correct endpoint URL for your agent, and modify thetask as desired):
Resources
Want more info on developing and deploying agents on Blaxel? Check out the following resources:Use OpenAI Agents SDK with Blaxel Sandboxes
Build compute-capable agents backed by Blaxel sandboxes using OpenAI Agents SDK.
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.
