OpenAI Agents API
Use Orble boxes as self-hosted environments for the OpenAI Agents API. codex exec-server runs in the box and connects to the session over an outbound WebSocket. Guest memory and process state are preserved when the box is suspended between turns, so the same executor reconnects on resume.
Create an Orble API key in Settings, an OpenAI API key, and an environment key on the Agents tab of the OpenAI platform dashboard. Pass only the environment key into the box, as CODEX_API_KEY.
$ pip install orble-sdk openai$ export ORBLE_API_KEY=orble_...$ export OPENAI_API_KEY=sk-...$ export OPENAI_EXECUTOR_API_KEY=sk-...$ python main.py
import os
import orble
from openai import OpenAI
client = OpenAI()
session = client.beta.agents.sessions.create(
agent={"model": "gpt-5.6-sol"},
environment={"type": "self_hosted", "workspace_directory": "/workspace"},
)
box = orble.create()
box.keep_awake()
box.exec("sudo mkdir -p /workspace && sudo chown agent /workspace"
" && npm install -g @openai/codex@alpha", timeout=300)
box.exec(
"setsid nohup codex exec-server"
f" --remote {session.environment.remote_url}"
f" --environment-id {session.environment.id}"
" > /tmp/codex-executor.log 2>&1 < /dev/null &",
cwd="/workspace",
env={"CODEX_API_KEY": os.environ["OPENAI_EXECUTOR_API_KEY"]},
)
with client.beta.agents.sessions.stream(
session.id, input="Write hello to hello.txt."
) as events:
for event in events:
if event.type == "agent.session.turn.output_text.delta":
print(event.delta, end="")
print(box.read("/workspace/hello.txt"))
box.suspend() # files, memory and the executor are kept until box.resume()
ExecutorCreate one box per session. Install the executor with
npm install -g @openai/codex@alphaand runcodex exec-serverin the background with the session'sremote_urland environment IDKeep awakeDisable automatic suspension while a turn runs, so the box stays up while the model works between commands
Between turnsSuspend the box, or restore automatic suspension, to stop CPU charges. Files, memory and the running executor are preserved. Resume the box before sending the next input
WebhooksCreate or resume the box on
agent.session.action_requiredwith anenvironment_connectionaction, disable automatic suspension onagent.session.in_progress, restore it onagent.session.idle, and delete the box onagent.session.failedCleanupDelete the box and the session separately. Deleting a session leaves its box running
NetworkThe executor needs outbound HTTPS to
api.openai.comandcodex-cloud-environments.chatgpt.com. With Orble Pro egress rules, allow both hosts