🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org
Python agentai-societiesartificial-intelligencecommunicative-aicooperative-aideep-learninglarge-language-modelsmulti-agent-systemsnatural-language-processing
docs: document browser console exec trust boundary (#4157)
Todd0585056eb2c8
diff --git a/camel/toolkits/hybrid_browser_toolkit/hybrid_browser_toolkit_ts.py b/camel/toolkits/hybrid_browser_toolkit/hybrid_browser_toolkit_ts.pyindex e1c8a7c11..3180a552d 100644--- a/camel/toolkits/hybrid_browser_toolkit/hybrid_browser_toolkit_ts.py+++ b/camel/toolkits/hybrid_browser_toolkit/hybrid_browser_toolkit_ts.py@@ -1417,11 +1417,16 @@ class HybridBrowserToolkit(BaseToolkit, RegisteredAgentToolkit):return {"console_messages": []}async def browser_console_exec(self, code: str) -> Dict[str, Any]:- r"""Execute javascript code in the console of the current page and get+ r"""Execute JavaScript code in the current page context and returnresults.+ This tool is not a sandbox: code runs with the active page's DOM,+ storage, cookies, and network access. Only enable or call it for+ trusted pages, trusted tasks, and trusted agent policies.+Args:- code (str): JavaScript code to execute in the browser console.+ code (str): JavaScript code to execute in the current page+ context.Returns:Dict[str, Any]: A dictionary with the result of the action:diff --git a/camel/toolkits/hybrid_browser_toolkit/ts/src/hybrid-browser-toolkit.ts b/camel/toolkits/hybrid_browser_toolkit/ts/src/hybrid-browser-toolkit.tsindex 44b34da6c..b33abf1fa 100644--- a/camel/toolkits/hybrid_browser_toolkit/ts/src/hybrid-browser-toolkit.ts+++ b/camel/toolkits/hybrid_browser_toolkit/ts/src/hybrid-browser-toolkit.ts@@ -619,6 +619,8 @@ export class HybridBrowserToolkit {let result;try {+ // Trust boundary: this intentionally executes caller-provided+ // JavaScript in the active page context, not in a sandbox.result = eval(${JSON.stringify(code)});} catch (e) {try {diff --git a/test/toolkits/test_hybrid_browser_toolkit.py b/test/toolkits/test_hybrid_browser_toolkit.pyindex 5541423de..e039b6f60 100644--- a/test/toolkits/test_hybrid_browser_toolkit.py+++ b/test/toolkits/test_hybrid_browser_toolkit.py@@ -580,6 +580,25 @@ class TestHybridBrowserToolkit:assert "tabs" in resultassert "result" in result["result"].lower()+ def test_console_exec_tool_schema_documents_trust_boundary(self):+ """Test console_exec tool schema documents its trust boundary."""+ toolkit = HybridBrowserToolkit(+ headless=True,+ enabled_tools=["browser_console_exec"],+ )+ tool = toolkit.get_tools()[0]+ schema = tool.get_openai_tool_schema()++ description = schema["function"]["description"].lower()+ code_description = schema["function"]["parameters"]["properties"][+ "code"+ ]["description"].lower()++ assert "current page context" in description+ assert "not a sandbox" in description+ assert "trusted" in description+ assert "javascript" in code_description+def test_get_tools(self, sync_browser_toolkit):"""Test getting available tools with default configuration."""toolkit = sync_browser_toolkit