Prerequisites
Before starting, ensure you have:- a Python or TypeScript development environment;
- a Blaxel account and API key. If not, sign up for a Blaxel account and create a Blaxel API key;
- an OpenAI API key with access to Codex. If not, create an OpenAI API key.
Install the Blaxel CLI and SDK
-
Download and install the Blaxel CLI and log in to your Blaxel account:
-
In a new directory, install the Blaxel SDK (Python and TypeScript are both supported):
Create sandboxes
-
In the host environment, define the following variables:
-
Create a script named
main.py(Python) orindex.ts(TypeScript) in the same directory.This script creates two Blaxel sandboxes:codex-sandboxusing Blaxel’s pre-built Codex image, which includes the Codex CLInextjs-sandboxusing Blaxel’s Next.js base image
- adds the Blaxel and OpenAI API keys to
codex-sandboxas environment variables.
- starts the Next.js dev server in
nextjs-sandboxon port 3000; - creates a preview URL for the Next.js service running in
nextjs-sandboxon port 3000; - creates an access token for the preview URL, valid for 24 hours;
- returns the preview URL.
-
Run the script to create the sandboxes and preview URL:
Once complete, the script displays the generated preview URL for the Next.js application (for example,
https://b186....preview.bl.run?bl_preview_token=cbba622560db78e...) and the MCP server URL (for example,https://sbx-nextjs-sandbox....bl.run/mcp) for the Next.js sandbox. Note these values, as you will require them in subsequent steps.
Configure and test Codex
-
Connect to the Codex sandbox terminal:
-
Configure Codex to connect to the application sandbox’s MCP server URL (obtained from the sandbox creation script in the previous section) with your Blaxel API key (set in the sandbox environment):
-
Start Codex and confirm that it is connected to the sandbox MCP server with the
/mcpcommand. This command should return the list of tools available in the sandbox.
Test Codex
Once Codex starts, give it a coding task referencing the application sandbox, as in the example prompt below:Resources
Want more information on building and deploying with OpenAI 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 on Blaxel
Build and deploy agents with OpenAI Agents SDK to Blaxel.
