8000 [Computer/Agent] Add Sandboxed Python Execution API, Stability Fixes by ddupont808 · Pull Request #281 · trycua/cua · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[Computer/Agent] Add Sandboxed Python Execution API, Stability Fixes #281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jun 5, 2025

Conversation

ddupont808
Copy link
Contributor

Overview
This PR introduces an API for sandboxed Python code execution in C/ua Containers. It also brings stability fixes and introduces pytest-based tests, an important step towards enabling smooth evaluation of multi-agent workflows on C/ua containers.

app-use Experiment Bug Fixes

  • Added stack trace logging for app-use errors
  • Fixed errors when left_click() is called without coordinates
  • Saved last known mouse position per App-use session to fix scrolling

Agent Bug Fixes

Computer

  • Added @sandboxed decorator in computer.helpers for running functions in a named venv inside the C/ua Container
  • Added support for creating/installing packages in venvs and executing code/commands within them
  • Added an asyncio.Lock to the command methods to prevent recv() errors when running agents in parallel

Tests

  • Added tests/venv.py for venv creation, execution, and decorator tests
  • Added tests/pytest.ini for asyncio support

Usage

# Example: Use @sandboxed to execute code in a C/ua Container
from computer.computer import Computer
from computer.helpers import sandboxed

computer = Computer()
await computer.run()

# 1. Install a package in a Python virtual environment
await computer.venv_install("demo_venv", ["requests", "macos-pyxa"])

# 2. Define a sandboxed function
@sandboxed("demo_venv")
def greet_and_print(name):
    # get .html of the current Safari tab
    import PyXA
    safari = PyXA.Application("Safari")
    current_doc = safari.current_document
    html = current_doc.source()
    print(f"Hello from inside the container, {name}!")
    print("Safari HTML length:", len(html))
    return {"greeted": name, "safari_html_length": len(html), "safari_html_snippet": html[:200]}

# 3. Run the function in the C/ua container in the agent's user session
result = await greet_and_print("C/ua")
# The print output and Safari HTML info will be forwarded and visible in your logs or output,
# and the result will include the greeting and a snippet/length of the Safari tab's HTML.

@ddupont808 ddupont808 merged commit 8d5690e into main Jun 5, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Agent / Computer] Can't type Unicode characters [Agent] Retry if UI-Tars HF warming up
2 participants
0