Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

feat: add OpenAI Bash tool using shared executor

Magnus Mueller461d97ed5ae4
diff --git a/browser_use/integrations/openai/__init__.py b/browser_use/integrations/openai/__init__.py
index e41399a5d..19e5b4679 100644
--- a/browser_use/integrations/openai/__init__.py
+++ b/browser_use/integrations/openai/__init__.py
@@ -1,5 +1,6 @@
"""Connect OpenAI browser tools to Browser Use actions."""
+from .bash import Bash
from .browser_use import BrowserUse
-__all__ = ['BrowserUse']
+__all__ = ['Bash', 'BrowserUse']
diff --git a/browser_use/integrations/openai/bash.py b/browser_use/integrations/openai/bash.py
new file mode 100644
index 000000000..ab0b69c23
--- /dev/null
+++ b/browser_use/integrations/openai/bash.py
@@ -0,0 +1,40 @@
+"""Expose the shared Bash executor through OpenAI's tool runner."""
+
+from pathlib import Path
+
+from pydantic import BaseModel, ConfigDict
+
+from browser_use.integrations.anthropic.bash import run_bash
+from openai import pydantic_responses_function_tool
+from openai.lib.responses_tool_runner import AsyncRegisteredFunction
+
+
+class BashInput(BaseModel):
+ model_config = ConfigDict(extra='forbid')
+ command: str
+
+
+def Bash(
+ *,
+ output_dir: str | Path = 'outputs',
+ timeout_seconds: float = 120,
+ max_output_bytes: int = 50_000,
+) -> AsyncRegisteredFunction:
+ """Create an OpenAI Bash tool with bounded execution and output."""
+
+ async def execute(args: BashInput) -> str:
+ return await run_bash(
+ args.command,
+ output_dir=output_dir,
+ timeout_seconds=timeout_seconds,
+ max_output_bytes=max_output_bytes,
+ )
+
+ return AsyncRegisteredFunction.from_tool(
+ pydantic_responses_function_tool(
+ BashInput,
+ name='bash',
+ description='Run Bash for computation and create files in the output directory. Use browser tools for browser actions.',
+ ),
+ execute=execute,
+ )
diff --git a/tests/ci/integrations/test_openai_browser_use.py b/tests/ci/integrations/test_openai_browser_use.py
index b36f7ea3f..ce7adfc50 100644
--- a/tests/ci/integrations/test_openai_browser_use.py
+++ b/tests/ci/integrations/test_openai_browser_use.py
@@ -3,7 +3,9 @@ from __future__ import annotations
import base64
import json
import re
+from collections.abc import Awaitable, Callable
from io import BytesIO
+from typing import cast
import pytest
from openai.lib.browser import AsyncBrowserToolset, BrowserError
@@ -220,3 +222,17 @@ async def test_screenshot_and_pointer_share_css_pixels_at_double_scale(driver):
assert image.convert('RGB').getpixel((110, 110)) == (0, 0, 255)
await driver.click_at({'tab_id': None, 'x': 150, 'y': 125, 'button': 'left', 'click_count': 1, 'keys': []})
assert await page.evaluate('() => document.title') == 'Clicked'
+
+
+async def test_openai_bash_creates_deliverable_without_inherited_secrets(tmp_path, monkeypatch):
+ from browser_use.integrations.openai import Bash
+ from browser_use.integrations.openai.bash import BashInput
+
+ monkeypatch.setenv('OPENAI_API_KEY', 'private-test-value')
+ tool = Bash(output_dir=tmp_path)
+ execute = cast(Callable[[BashInput], Awaitable[str]], tool.execute)
+ result = json.loads(await execute(BashInput(command='printf result > report.txt; printenv OPENAI_API_KEY || true')))
+ assert result['exit_code'] == 0
+ assert result['output'] == ''
+ assert (tmp_path / 'report.txt').read_text() == 'result'