Skip to main content

modal-openai

Run OpenAI Agents in Modal Sandboxes. OpenAI runs the agent; Modal provides an isolated environment where it can run commands and edit files.

Getting started

You need Python 3.12+, uv, a Modal account, and an OpenAI project with Agents API access. Your GitHub account must have access to the Agents API SDK.

git clone https://github.com/modal-labs/modal-openai.git
cd modal-openai
uv sync --locked
uv run modal setup
uv run modal-agents init research-agent

Setup guides you through selecting or creating an agent, configuring credentials, and deploying its sandbox configuration. Have your OpenAI application key and a separate restricted executor key ready. See credentials for the required permissions.

When prompted, register the supplied URL in OpenAI Project Webhooks for agent.session.action_required and agent.session.failed, then paste the signing secret back into setup.

Get a response

Ask the agent to run a command and tell you a joke:

uv run modal-agents smoke research-agent \
  --prompt "Use the shell to print hello, then tell me a joke."

The command prints the agent's response and cleans up the test session and sandbox. It uses your OpenAI application key and incurs normal OpenAI and Modal usage charges.

For sessions in your own application, see examples/session.py. Use the agent ID saved in agents/research-agent.py and the same workspace path (default /workspace).

Configure the sandbox

Edit agents/research-agent.py to choose the image, CPU, memory, GPU, and timeout. For example, add .pip_install("pandas", "matplotlib") to the image for data analysis, or set gpu="A10G" for GPU workloads.

Deploy your changes:

uv run modal-agents deploy research-agent

New sandboxes use the updated configuration. Files remain available for the sandbox's lifetime, which defaults to 30 minutes.

More

License

MIT.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

modal_openai-0.1.0.tar.gz (185.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

modal_openai-0.1.0-py3-none-any.whl (25.0 kB view details)

Uploaded Python 3

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page