Skip to main content
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 use the OpenAI Agents SDK with Blaxel to create powerful sandbox-backed agents.

Prerequisites

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 with the Python SDK.

1. Install the Blaxel CLI and log in to Blaxel

Install the Blaxel CLI and log in to Blaxel using this command:

2. Install required dependencies

Create a directory for the project:
In your project directory, install the OpenAI Agent SDK with Blaxel support for the agent loop:

3. Configure the environment

Add your OpenAI API key, Blaxel API key and Blaxel workspace name as environment variables:

4. Build a simple agent

In your project directory, create a file named index.ts (TypeScript) or main.py (Python) with the following code.
This creates a simple sandbox-backed agent with the OpenAI Agents SDK. Instructions that you send the agent will be executed in a sandbox named agent-sandbox-01 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:

5. Build a data analysis agent

In addition to running commands, agents can also create, delete and manage files and directories in the sandbox filesystem. Generated files can be transferred from the sandbox environment to the host (and vice-versa). To see this in action, update the simple agent from the previous example to perform data processing and analysis in a sandbox:
In this example, the agent uses Blaxel’s blaxel/py-app image to create a sandbox containing a complete Python development environment. When the sandbox is created, the SDK automatically also creates a new workspace directory (defaults to /workspace but can be configured to point to another location) for the agent to operate in. The agent then uses sandbox tools to call the remote API, obtains a dataset (mock data), and autonomously installs all the required packages for chart creation. It then prepares and saves a chart of the received data to the workspace at /workspace/chart.png. This file is then read from the sandbox session and downloaded to the local host. Once the session is complete, the sandbox is terminated. Run the agent - once complete, you will have a new chart.png file in your project directory containing the generated chart. This example also demonstrates the SDK’s streaming capabilities - you will see a stream of the agent’s reasoning as it works.

6. Build a 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. Blaxel sandboxes offer a unique advantage here: human operators can preview agent-generated applications in real-time via direct preview URLs for each running sandbox. To see this in practice, update the agent code in index.ts / main.py as below:
This creates a Next.js coding agent that accepts requests from the command-line. The coding agent’s sandbox is generated from Blaxel’s blaxel/nextjs image, which contains a complete Next.js development environment and a Next.js skeleton application. Notice the ttl parameter, which sets an expiration policy to automatically delete the sandbox after 30 minutes. In addition, the exposed_port_public parameter and the resolve_exposed_port() function call take care of producing a preview URL for the user, and the pause_on_exit parameter prevents the sandbox from being automatically deleted at the end of the session. Test the agent:
The agent will start working on the task in a sandbox, streaming its responses as it works. Once it is complete, you should see a preview URL similar to the following:
Open the preview URL in your browser to see the results of the agent’s work. That’s it! You’re ready to start building and deploying Blaxel sandbox-backed agents with OpenAI Agents SDK on Blaxel.

Resources

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

Run OpenAI Agents SDK agents on Blaxel

You don’t have to stop at the sandboxes! Deploy OpenAI Agents SDK on Blaxel.

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.
Last modified on May 14, 2026