How to Intermediate · 3 min read

How to sandbox computer use agents

Quick answer
Use the OpenAI Python SDK with the tools parameter specifying a computer_20241022 tool and enable the computer-use-2024-10-22 beta flag to sandbox computer use agents securely. This setup restricts the agent's environment and capabilities for safe execution.

PREREQUISITES

  • Python 3.8+
  • OpenAI API key
  • pip install openai>=1.0

Setup

Install the latest openai Python SDK and set your API key as an environment variable.

bash
pip install --upgrade openai
output
Collecting openai
  Downloading openai-1.x.x-py3-none-any.whl (xx kB)
Installing collected packages: openai
Successfully installed openai-1.x.x

Step by step

This example demonstrates how to create a sandboxed computer use agent using the OpenAI SDK. It configures the tools parameter with the computer_20241022 tool and enables the required beta flag.

python
import os
from openai import OpenAI

client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])

response = client.chat.completions.create(
    model="gpt-4o-mini",
    tools=[{
        "type": "computer_20241022",
        "name": "computer",
        "display_width_px": 1024,
        "display_height_px": 768
    }],
    betas=["computer-use-2024-10-22"],
    messages=[{"role": "user", "content": "Run a safe Python script that lists files in the sandbox."}]
)

print(response.choices[0].message.content)
output
Sandboxed file list:
- README.md
- main.py
- data.csv

Common variations

  • Use gpt-4o or other supported models for more capability.
  • Switch to async calls with asyncio and await for concurrency.
  • Adjust display_width_px and display_height_px to simulate different screen sizes.
python
import asyncio
from openai import OpenAI

async def main():
    client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
    response = await client.chat.completions.acreate(
        model="gpt-4o",
        tools=[{
            "type": "computer_20241022",
            "name": "computer",
            "display_width_px": 1280,
            "display_height_px": 720
        }],
        betas=["computer-use-2024-10-22"],
        messages=[{"role": "user", "content": "Check system info in sandbox."}]
    )
    print(response.choices[0].message.content)

asyncio.run(main())
output
Sandboxed system info:
OS: Linux
CPU: 4 cores
Memory: 8GB

Troubleshooting

  • If you get an error about missing beta flags, ensure betas=["computer-use-2024-10-22"] is included in the request.
  • Verify your API key has access to the computer use beta features.
  • Check that the tools parameter uses the exact computer_20241022 type; other values will fail.

Key Takeaways

  • Use the OpenAI SDK's tools parameter with type 'computer_20241022' to sandbox computer use agents.
  • Always include the beta flag 'computer-use-2024-10-22' to enable sandboxed computer capabilities.
  • Adjust display dimensions to simulate different sandbox environments.
  • Use async calls for scalable and concurrent sandboxed agent interactions.
  • Check API key permissions and beta flag inclusion if sandbox features fail.
Verified 2026-04 · gpt-4o-mini, gpt-4o
Verify ↗