Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
Setup UV as venv manager for computer (#789)
Harsh Verma0f1bbced7158
diff --git a/libs/kasm/Dockerfile b/libs/kasm/Dockerfileindex 89d447cfca..3aae33fb1a 100644--- a/libs/kasm/Dockerfile+++ b/libs/kasm/Dockerfile@@ -8,29 +8,46 @@ WORKDIR $HOME######### Customize Container Here ###########-# Installing python, pip, and libraries-RUN apt-get update-RUN apt install -y wget build-essential libncursesw5-dev libssl-dev \-libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev-RUN add-apt-repository ppa:deadsnakes/ppa-RUN apt install -y python3.11 python3-pip python3-tk python3-dev \-gnome-screenshot wmctrl ffmpeg socat xclip+# Installing python, pip, and libraries (but don't change default yet)+RUN apt-get update && \+ apt install -y wget build-essential libncursesw5-dev libssl-dev \+ libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev && \+ add-apt-repository ppa:deadsnakes/ppa && \+ apt-get update && \+ apt install -y python3.12 python3.12-dev python3.12-tk \+ gnome-screenshot wmctrl ffmpeg socat xclip curl && \+ apt-get clean && rm -rf /var/lib/apt/lists/*-RUN pip install cua-computer-server--# Install Firefox+# Install Firefox (do this BEFORE changing default Python, as add-apt-repository needs system Python)ENV DEBIAN_FRONTEND=noninteractive \INST_DIR=$STARTUPDIR/installCOPY ./src/ $INST_DIRRUN bash ${INST_DIR}/ubuntu/install/firefox/install_firefox.sh+# Now set Python 3.12 as the default python3+RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1 && \+ update-alternatives --set python3 /usr/bin/python3.12++# Install pip for Python 3.12+RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python3.12++# Install UV package manager+RUN python3.12 -m pip install uv++# Install cua-computer-server+RUN uv pip install --system cua-computer-server++# Install playwright and Firefox dependencies+RUN uv pip install --system playwright && \+ python3.12 -m playwright install --with-deps firefox+# Disable SSL requirementRUN sed -i 's/require_ssl: true/require_ssl: false/g' /usr/share/kasmvnc/kasmvnc_defaults.yamlRUN sed -i 's/-sslOnly//g' /dockerstartup/vnc_startup.sh# Running the python script on startupRUN echo "/usr/bin/python3 -m computer_server" > $STARTUPDIR/custom_startup.sh \-&& chmod +x $STARTUPDIR/custom_startup.sh+ && chmod +x $STARTUPDIR/custom_startup.sh# Enable sudo support for kasm-userRUN echo "kasm-user:password" | chpasswddiff --git a/libs/python/computer-server/computer_server/handlers/android.py b/libs/python/computer-server/computer_server/handlers/android.pyindex 952449a672..2e599cb6fe 100644--- a/libs/python/computer-server/computer_server/handlers/android.py+++ b/libs/python/computer-server/computer_server/handlers/android.py@@ -495,9 +495,53 @@ class AndroidAutomationHandler(BaseAutomationHandler):# Otherasync def run_command(self, command: str) -> Dict[str, Any]:- """Run a shell command on Android device."""- success, output = await adb_exec.run("shell", command, decode=True)- return {"output": output, "success": success}+ """Run a shell command.++ Commands containing 'uv', 'python', or '/home/androidusr' run on the container host.+ Other commands run in the Android emulator via adb shell.+ """+ # Check if this command should run on the host+ should_run_on_host = any(+ keyword in command for keyword in ["uv", "python", "/home/androidusr"]+ )++ if should_run_on_host:+ # Run on container host+ import os+ import subprocess++ try:+ # Clear VIRTUAL_ENV to avoid UV conflicts+ env = os.environ.copy()+ env.pop("VIRTUAL_ENV", None)++ result = subprocess.run(+ command, shell=True, capture_output=True, text=True, timeout=300, env=env+ )+ return {+ "stdout": result.stdout,+ "stderr": result.stderr,+ "return_code": result.returncode,+ "success": result.returncode == 0,+ }+ except subprocess.TimeoutExpired:+ return {+ "stdout": "",+ "stderr": "Command timed out",+ "return_code": -1,+ "success": False,+ }+ except Exception as e:+ return {"stdout": "", "stderr": str(e), "return_code": -1, "success": False}+ else:+ # Run in Android emulator via adb shell+ success, output = await adb_exec.run("shell", command, decode=True)+ return {+ "stdout": output if success else "",+ "stderr": "" if success else output,+ "return_code": 0 if success else 1,+ "success": success,+ }class AndroidFileHandler(BaseFileHandler):diff --git a/libs/python/computer/computer/computer.py b/libs/python/computer/computer/computer.pyindex b4d1ce06ea..9dabcab781 100644--- a/libs/python/computer/computer/computer.py+++ b/libs/python/computer/computer/computer.py@@ -34,7 +34,7 @@ from core.telemetry import is_telemetry_enabled, record_eventfrom PIL import Imagefrom . import helpers-from .interface.factory import InterfaceFactory+from .interface.factory import InterfaceFactory, OSTypefrom .logger import Logger, LogLevelfrom .models import Computer as ComputerConfigfrom .models import Display@@ -59,6 +59,7 @@ except ImportError:def is_otel_enabled() -> bool:return False+SYSTEM_INFO = {"os": platform.system().lower(),"os_version": platform.release(),@@ -69,8 +70,6 @@ SYSTEM_INFO = {from .providers.base import VMProviderTypefrom .providers.factory import VMProviderFactory-OSType = Literal["macos", "linux", "windows", "android"]-class Computer:"""Computer is the main class for interacting with the computer."""@@ -127,7 +126,7 @@ class Computer:Defaults to "1024x768"memory: The VM memory allocation. Defaults to "8GB"cpu: The VM CPU allocation. Defaults to "4"- os_type: The operating system type ('macos' or 'linux')+ os_type: The operating system type ('macos', 'linux', 'windows', 'android')name: The VM nameimage: The VM image nameshared_directories: Optional list of directory paths to share with the VM@@ -1028,13 +1027,8 @@ class Computer:and self._original_interface is not None):# Create OTEL wrapper if it doesn't exist- if (- not hasattr(self, "_otel_wrapper")- or self._otel_wrapper is None- ):- self._otel_wrapper = OtelInterfaceWrapper(- self._original_interface, self.os_type- )+ if not hasattr(self, "_otel_wrapper") or self._otel_wrapper is None:+ self._otel_wrapper = OtelInterfaceWrapper(self._original_interface, self.os_type)result_interface = self._otel_wrapper# Return tracing wrapper if tracing is active and we have an original interface@@ -1129,10 +1123,10 @@ class Computer:# Add virtual environment management functions to computer interfaceasync def venv_install(self, venv_name: str, requirements: list[str]):- """Install packages in a virtual environment.+ """Install packages in a UV project.Args:- venv_name: Name of the virtual environment+ venv_name: Name of the UV projectrequirements: List of package requirements to installReturns:@@ -1144,35 +1138,40 @@ class Computer:# Use %USERPROFILE% for home directory and cmd.exe semanticsvenv_path = f"%USERPROFILE%\\.venvs\\{venv_name}"ensure_dir_cmd = 'if not exist "%USERPROFILE%\\.venvs" mkdir "%USERPROFILE%\\.venvs"'- create_cmd = f'if not exist "{venv_path}" python -m venv "{venv_path}"'- requirements_str = " ".join(requirements)- # Activate via activate.bat and install- install_cmd = (- f'call "{venv_path}\\Scripts\\activate.bat" && pip install {requirements_str}'- if requirements_str- else "echo No requirements to install"- )+ # Initialize UV project if it doesn't exist+ create_cmd = f'if not exist "{venv_path}" uv init --vcs none --no-readme --no-workspace --no-pin-python "{venv_path}"'await self.interface.run_command(ensure_dir_cmd)await self.interface.run_command(create_cmd)- return await self.interface.run_command(install_cmd)+ # Install packages+ if requirements_str := " ".join(requirements):+ install_cmd = f'uv add --directory "{venv_path}" {requirements_str}'+ return await self.interface.run_command(install_cmd)+ return await self.interface.run_command("echo No requirements to install")+ elif self.os_type == "android":+ # Android: Use hardcoded path as $HOME may not be set+ venv_path = f"/home/androidusr/.venvs/{venv_name}"+ # Initialize UV project if it doesn't exist+ create_cmd = f'mkdir -p "/home/androidusr/.venvs" && (test -d "{venv_path}" || uv init --vcs none --no-readme --no-workspace --no-pin-python "{venv_path}")'+ await self.interface.run_command(create_cmd)+ # Install packages+ if requirements_str := " ".join(requirements):+ install_cmd = f'uv add --directory "{venv_path}" {requirements_str}'+ return await self.interface.run_command(install_cmd)+ return await self.interface.run_command("echo No requirements to install")else:# POSIX (macOS/Linux)venv_path = f"$HOME/.venvs/{venv_name}"- create_cmd = f'mkdir -p "$HOME/.venvs" && python -m venv "{venv_path}"'- # Check if venv exists, if not create it- check_cmd = f'test -d "{venv_path}" || ({create_cmd})'- _ = await self.interface.run_command(check_cmd)+ # Initialize UV project if it doesn't exist+ create_cmd = f'mkdir -p "$HOME/.venvs" && (test -d "{venv_path}" || uv init --vcs none --no-readme --no-workspace --no-pin-python "{venv_path}")'+ await self.interface.run_command(create_cmd)# Install packages- requirements_str = " ".join(requirements)- install_cmd = (- f'. "{venv_path}/bin/activate" && pip install {requirements_str}'- if requirements_str- else "echo No requirements to install"- )- return await self.interface.run_command(install_cmd)+ if requirements_str := " ".join(requirements):+ install_cmd = f'uv add --directory "{venv_path}" {requirements_str}'+ return await self.interface.run_command(install_cmd)+ return await self.interface.run_command("echo No requirements to install")async def pip_install(self, requirements: list[str]):- """Install packages using the system Python/pip (no venv).+ """Install packages using the system Python with UV (no venv).Args:requirements: List of package requirements to install globally/user site.@@ -1184,44 +1183,57 @@ class Computer:if not requirements:return await self.interface.run_command("echo No requirements to install")- # Use python -m pip for cross-platform consistencyreqs = " ".join(requirements)- install_cmd = f"python -m pip install {reqs}"+ install_cmd = f"uv pip install --system {reqs}"return await self.interface.run_command(install_cmd)async def venv_cmd(self, venv_name: str, command: str):- """Execute a shell command in a virtual environment.+ """Execute a shell command in a UV project.Args:- venv_name: Name of the virtual environment- command: Shell command to execute in the virtual environment+ venv_name: Name of the UV project+ command: Shell command to execute in the UV projectReturns:Tuple of (stdout, stderr) from the command execution"""if self.os_type == "windows":# Windows (cmd.exe)- venv_path = f"%USERPROFILE%\\.venvs\\{venv_name}"+ project_path = f"%USERPROFILE%\\.venvs\\{venv_name}"# Check existence and signal if missing- check_cmd = f'if not exist "{venv_path}" (echo VENV_NOT_FOUND) else (echo VENV_FOUND)'+ check_cmd = (+ f'if not exist "{project_path}" (echo VENV_NOT_FOUND) else (echo VENV_FOUND)'+ )result = await self.interface.run_command(check_cmd)if "VENV_NOT_FOUND" in getattr(result, "stdout", ""):- # Auto-create the venv with no requirements+ # Auto-create the UV project with no requirements+ await self.venv_install(venv_name, [])+ # Execute command in project+ full_command = f'uv run --directory "{project_path}" {command}'+ return await self.interface.run_command(full_command)+ elif self.os_type == "android":+ # Android: Use hardcoded path as $HOME may not be set+ project_path = f"/home/androidusr/.venvs/{venv_name}"+ # Check if UV project exists+ check_cmd = f'test -d "{project_path}"'+ result = await self.interface.run_command(check_cmd)+ if result.stderr or "test:" in result.stdout: # project doesn't exist+ # Auto-create the UV project with no requirementsawait self.venv_install(venv_name, [])- # Activate and run the command- full_command = f'call "{venv_path}\\Scripts\\activate.bat" && {command}'+ # Execute command in project+ full_command = f'uv run --directory "{project_path}" {command}'return await self.interface.run_command(full_command)else:# POSIX (macOS/Linux)- venv_path = f"$HOME/.venvs/{venv_name}"- # Check if virtual environment exists- check_cmd = f'test -d "{venv_path}"'+ project_path = f"$HOME/.venvs/{venv_name}"+ # Check if UV project exists+ check_cmd = f'test -d "{project_path}"'result = await self.interface.run_command(check_cmd)- if result.stderr or "test:" in result.stdout: # venv doesn't exist- # Auto-create the venv with no requirements+ if result.stderr or "test:" in result.stdout: # project doesn't exist+ # Auto-create the UV project with no requirementsawait self.venv_install(venv_name, [])- # Activate virtual environment and run command- full_command = f'. "{venv_path}/bin/activate" && {command}'+ # Execute command in project+ full_command = f'uv run --directory "{project_path}" {command}'return await self.interface.run_command(full_command)async def venv_exec(self, venv_name: str, python_func, *args, **kwargs):@@ -1307,6 +1319,20 @@ print(f"<<<VENV_EXEC_START>>>{{output_json}}<<<VENV_EXEC_END>>>")# Encode the Python code in base64 to avoid shell escaping issuesencoded_code = base64.b64encode(python_code.encode("utf-8")).decode("ascii")+ # Detect if function is async+ import inspect++ is_async = inspect.iscoroutinefunction(python_func)++ # Update the execution code to handle async functions+ if is_async:+ # For async functions, we need to run them with asyncio+ python_code = python_code.replace(+ f"result = {func_name}(*args, **kwargs)",+ f"import asyncio\n result = asyncio.run({func_name}(*args, **kwargs))",+ )+ encoded_code = base64.b64encode(python_code.encode("utf-8")).decode("ascii")+# Execute the Python code in the virtual environmentpython_command = (f"python -c \"import base64; exec(base64.b64decode('{encoded_code}').decode('utf-8'))\""@@ -1384,12 +1410,23 @@ print(f"<<<VENV_EXEC_START>>>{{output_json}}<<<VENV_EXEC_END>>>")reqs_list = requirements or []reqs_json = json.dumps(reqs_list)+ # Detect if function is async+ import inspect++ is_async = inspect.iscoroutinefunction(python_func)+# Create Python code that will define and execute the functionargs_b64 = base64.b64encode(args_json.encode("utf-8")).decode("ascii")kwargs_b64 = base64.b64encode(kwargs_json.encode("utf-8")).decode("ascii")- payload_code = (- f'''+ # Choose the execution statement based on whether function is async+ exec_statement = (+ f"import asyncio\n _ = asyncio.run({func_name}(*args, **kwargs))"+ if is_async+ else f"_ = {func_name}(*args, **kwargs)"+ )++ payload_code = f'''import jsonimport tracebackimport base64@@ -1397,67 +1434,106 @@ import base64try:# Define the function from source{textwrap.indent(func_source, " ")}-+# Deserialize args and kwargs from base64 JSON_args_b64 = """{args_b64}"""_kwargs_b64 = """{kwargs_b64}"""args = json.loads(base64.b64decode(_args_b64).decode('utf-8'))kwargs = json.loads(base64.b64decode(_kwargs_b64).decode('utf-8'))-- # Ensure requirements inside the active venv- for pkg in json.loads('''- + repr(reqs_json)- + """):++ # Ensure requirements in UV project+ for pkg in json.loads({repr(reqs_json)}):if pkg:- import subprocess, sys- subprocess.run([sys.executable, '-m', 'pip', 'install', pkg], check=False)- _ = {func_name}(*args, **kwargs)+ import subprocess, sys, os+ # Get project path from current working directory (set by uv run)+ project_path = os.getcwd()+ subprocess.run(['uv', 'add', '--directory', project_path, pkg], check=False)+ {exec_statement}except Exception:import syssys.stderr.write(traceback.format_exc())-"""- )+'''payload_b64 = base64.b64encode(payload_code.encode("utf-8")).decode("ascii")+ # Auto-create UV project if needed+ await self.venv_install(venv_name, [])+if self.os_type == "windows":- # Launcher spawns detached child and prints its PID+ # Launcher spawns detached child using uv run and prints its PID+ venv_path = f"%USERPROFILE%\\.venvs\\{venv_name}"launcher_code = f"""import base64, subprocess, os, sysDETACHED_PROCESS = 0x00000008CREATE_NEW_PROCESS_GROUP = 0x00000200creationflags = DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUPcode = base64.b64decode("{payload_b64}").decode("utf-8")-p = subprocess.Popen(["python", "-c", code], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, creationflags=creationflags)+# Expand environment variables in path+venv_path = os.path.join(os.path.expandvars('%USERPROFILE%'), '.venvs', '{venv_name}')+p = subprocess.Popen(["uv", "run", "--directory", venv_path, "python", "-c", code], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, creationflags=creationflags, cwd=venv_path)print(p.pid)"""launcher_b64 = base64.b64encode(launcher_code.encode("utf-8")).decode("ascii")- venv_path = f"%USERPROFILE%\\.venvs\\{venv_name}"- cmd = (- 'cmd /c "'- f'call "{venv_path}\\Scripts\\activate.bat" && '- f"python -c \"import base64; exec(base64.b64decode('{launcher_b64}').decode('utf-8'))\""- '"'- )+ # Use UV to run the launcher code in the project+ cmd = f"uv run --directory \"{venv_path}\" python -c \"import base64; exec(base64.b64decode('{launcher_b64}').decode('utf-8'))\""result = await self.interface.run_command(cmd)- pid_str = (result.stdout or "").strip().splitlines()[-1].strip()+ stdout_lines = (result.stdout or "").strip().splitlines()+ if not stdout_lines:+ raise Exception(+ f"Failed to launch background process. No output received.\n"+ f"stdout: {result.stdout}\n"+ f"stderr: {result.stderr}"+ )+ pid_str = stdout_lines[-1].strip()return int(pid_str)- else:+ elif self.os_type == "android":log = f"/tmp/cua_bg_{int(_time.time())}.log"+ venv_path = f"/home/androidusr/.venvs/{venv_name}"launcher_code = f"""import base64, subprocess, os, syscode = base64.b64decode("{payload_b64}").decode("utf-8")+# Use hardcoded path for Android+venv_path = "/home/androidusr/.venvs/{venv_name}"with open("{log}", "ab", buffering=0) as f:- p = subprocess.Popen(["python", "-c", code], stdout=f, stderr=subprocess.STDOUT, preexec_fn=getattr(os, "setsid", None))+ p = subprocess.Popen(["uv", "run", "--directory", venv_path, "python", "-c", code], stdout=f, stderr=subprocess.STDOUT, preexec_fn=getattr(os, "setsid", None), cwd=venv_path)print(p.pid)"""launcher_b64 = base64.b64encode(launcher_code.encode("utf-8")).decode("ascii")+ # Run the launcher code in the project+ cmd = f"uv run --directory \"{venv_path}\" python -c \"import base64; exec(base64.b64decode('{launcher_b64}').decode('utf-8'))\""+ result = await self.interface.run_command(cmd)+ stdout_lines = (result.stdout or "").strip().splitlines()+ if not stdout_lines:+ raise Exception(+ f"Failed to launch background process. No output received.\n"+ f"stdout: {result.stdout}\n"+ f"stderr: {result.stderr}"+ )+ pid_str = stdout_lines[-1].strip()+ return int(pid_str)+ else:+ log = f"/tmp/cua_bg_{int(_time.time())}.log"venv_path = f"$HOME/.venvs/{venv_name}"- shell = (- f'. "{venv_path}/bin/activate" && '- f"python -c \"import base64; exec(base64.b64decode('{launcher_b64}').decode('utf-8'))\""- )- result = await self.interface.run_command(shell)- pid_str = (result.stdout or "").strip().splitlines()[-1].strip()+ launcher_code = f"""+import base64, subprocess, os, sys+code = base64.b64decode("{payload_b64}").decode("utf-8")+# Expand home directory in path+venv_path = os.path.join(os.path.expanduser('~'), '.venvs', '{venv_name}')+with open("{log}", "ab", buffering=0) as f:+ p = subprocess.Popen(["uv", "run", "--directory", venv_path, "python", "-c", code], stdout=f, stderr=subprocess.STDOUT, preexec_fn=getattr(os, "setsid", None), cwd=venv_path)+print(p.pid)+"""+ launcher_b64 = base64.b64encode(launcher_code.encode("utf-8")).decode("ascii")+ # Run the launcher code in the project+ cmd = f"uv run --directory \"{venv_path}\" python -c \"import base64; exec(base64.b64decode('{launcher_b64}').decode('utf-8'))\""+ result = await self.interface.run_command(cmd)+ stdout_lines = (result.stdout or "").strip().splitlines()+ if not stdout_lines:+ raise Exception(+ f"Failed to launch background process. No output received.\n"+ f"stdout: {result.stdout}\n"+ f"stderr: {result.stderr}"+ )+ pid_str = stdout_lines[-1].strip()return int(pid_str)async def python_exec(self, python_func, *args, **kwargs):@@ -1483,10 +1559,22 @@ print(p.pid)except Exception as e:raise Exception(f"Failed to reconstruct function source: {e}")+ # Detect if function is async+ import inspect++ is_async = inspect.iscoroutinefunction(python_func)+# Create Python code that will define and execute the functionargs_b64 = base64.b64encode(args_json.encode("utf-8")).decode("ascii")kwargs_b64 = base64.b64encode(kwargs_json.encode("utf-8")).decode("ascii")+ # Choose the execution statement based on whether function is async+ exec_statement = (+ f"import asyncio\n result = asyncio.run({func_name}(*args, **kwargs))"+ if is_async+ else f"result = {func_name}(*args, **kwargs)"+ )+python_code = f'''import jsonimport traceback@@ -1495,15 +1583,15 @@ import base64try:# Define the function from source{textwrap.indent(func_source, " ")}-+# Deserialize args and kwargs from base64 JSON_args_b64 = """{args_b64}"""_kwargs_b64 = """{kwargs_b64}"""args = json.loads(base64.b64decode(_args_b64).decode('utf-8'))kwargs = json.loads(base64.b64decode(_kwargs_b64).decode('utf-8'))-+# Execute the function- result = {func_name}(*args, **kwargs)+ {exec_statement}# Create success output payloadoutput_payload = {{@@ -1511,7 +1599,7 @@ try:"result": result,"error": None}}-+except Exception as e:# Create error output payloadoutput_payload = {{@@ -1533,9 +1621,9 @@ print(f"<<<VENV_EXEC_START>>>{{output_json}}<<<VENV_EXEC_END>>>")'''encoded_code = base64.b64encode(python_code.encode("utf-8")).decode("ascii")- python_command = (- f"python -c \"import base64; exec(base64.b64decode('{encoded_code}').decode('utf-8'))\""- )+ # Use python3 on POSIX systems, python on Windows+ python_cmd = "python" if self.os_type == "windows" else "python3"+ python_command = f"{python_cmd} -c \"import base64; exec(base64.b64decode('{encoded_code}').decode('utf-8'))\""result = await self.interface.run_command(python_command)start_marker = "<<<VENV_EXEC_START>>>"@@ -1596,10 +1684,22 @@ print(f"<<<VENV_EXEC_START>>>{{output_json}}<<<VENV_EXEC_END>>>")except Exception as e:raise Exception(f"Failed to reconstruct function source: {e}")+ # Detect if function is async+ import inspect++ is_async = inspect.iscoroutinefunction(python_func)+# Create Python code that will define and execute the functionargs_b64 = base64.b64encode(args_json.encode("utf-8")).decode("ascii")kwargs_b64 = base64.b64encode(kwargs_json.encode("utf-8")).decode("ascii")+ # Choose the execution statement based on whether function is async+ exec_statement = (+ f"import asyncio\n _ = asyncio.run({func_name}(*args, **kwargs))"+ if is_async+ else f"_ = {func_name}(*args, **kwargs)"+ )+payload_code = f'''import jsonimport traceback@@ -1608,14 +1708,14 @@ import base64try:# Define the function from source{textwrap.indent(func_source, " ")}-+# Deserialize args and kwargs from base64 JSON_args_b64 = """{args_b64}"""_kwargs_b64 = """{kwargs_b64}"""args = json.loads(base64.b64decode(_args_b64).decode('utf-8'))kwargs = json.loads(base64.b64decode(_kwargs_b64).decode('utf-8'))-- _ = {func_name}(*args, **kwargs)++ {exec_statement}except Exception:import syssys.stderr.write(traceback.format_exc())@@ -1633,9 +1733,17 @@ p = subprocess.Popen(["python", "-c", code], stdout=subprocess.DEVNULL, stderr=sprint(p.pid)"""launcher_b64 = base64.b64encode(launcher_code.encode("utf-8")).decode("ascii")+ # Use python on Windowscmd = f"python -c \"import base64; exec(base64.b64decode('{launcher_b64}').decode('utf-8'))\""result = await self.interface.run_command(cmd)- pid_str = (result.stdout or "").strip().splitlines()[-1].strip()+ stdout_lines = (result.stdout or "").strip().splitlines()+ if not stdout_lines:+ raise Exception(+ f"Failed to launch background process. No output received.\n"+ f"stdout: {result.stdout}\n"+ f"stderr: {result.stderr}"+ )+ pid_str = stdout_lines[-1].strip()return int(pid_str)else:log = f"/tmp/cua_bg_{int(_time.time())}.log"@@ -1643,13 +1751,21 @@ print(p.pid)import base64, subprocess, os, syscode = base64.b64decode("{payload_b64}").decode("utf-8")with open("{log}", "ab", buffering=0) as f:- p = subprocess.Popen(["python", "-c", code], stdout=f, stderr=subprocess.STDOUT, preexec_fn=getattr(os, "setsid", None))+ p = subprocess.Popen(["python3", "-c", code], stdout=f, stderr=subprocess.STDOUT, preexec_fn=getattr(os, "setsid", None))print(p.pid)"""launcher_b64 = base64.b64encode(launcher_code.encode("utf-8")).decode("ascii")- cmd = f"python -c \"import base64; exec(base64.b64decode('{launcher_b64}').decode('utf-8'))\""+ # Use python3 on POSIX systems+ cmd = f"python3 -c \"import base64; exec(base64.b64decode('{launcher_b64}').decode('utf-8'))\""result = await self.interface.run_command(cmd)- pid_str = (result.stdout or "").strip().splitlines()[-1].strip()+ stdout_lines = (result.stdout or "").strip().splitlines()+ if not stdout_lines:+ raise Exception(+ f"Failed to launch background process. No output received.\n"+ f"stdout: {result.stdout}\n"+ f"stderr: {result.stderr}"+ )+ pid_str = stdout_lines[-1].strip()return int(pid_str)def python_command(diff --git a/libs/python/computer/computer/interface/android.py b/libs/python/computer/computer/interface/android.pynew file mode 100644index 0000000000..dbc5708a94--- /dev/null+++ b/libs/python/computer/computer/interface/android.py@@ -0,0 +1,20 @@+from typing import Optional++from .generic import GenericComputerInterface+++class AndroidComputerInterface(GenericComputerInterface):+ """Interface for Android."""++ def __init__(+ self,+ ip_address: str,+ username: str = "lume",+ password: str = "lume",+ api_key: Optional[str] = None,+ vm_name: Optional[str] = None,+ api_port: Optional[int] = None,+ ):+ super().__init__(+ ip_address, username, password, api_key, vm_name, "computer.interface.android", api_port+ )diff --git a/libs/python/computer/computer/interface/factory.py b/libs/python/computer/computer/interface/factory.pyindex 4989ec9cd6..e2f3b5316c 100644--- a/libs/python/computer/computer/interface/factory.py+++ b/libs/python/computer/computer/interface/factory.py@@ -4,13 +4,15 @@ from typing import Literal, Optionalfrom .base import BaseComputerInterface+OSType = Literal["macos", "linux", "windows", "android"]+class InterfaceFactory:"""Factory for creating OS-specific computer interfaces."""@staticmethoddef create_interface_for_os(- os: Literal["macos", "linux", "windows"],+ os: OSType,ip_address: str,api_port: Optional[int] = None,api_key: Optional[str] = None,@@ -31,22 +33,30 @@ class InterfaceFactory:Raises:ValueError: If the OS type is not supported"""- # Import implementations here to avoid circular imports- from .linux import LinuxComputerInterface- from .macos import MacOSComputerInterface- from .windows import WindowsComputerInterfaceif os == "macos":+ from .macos import MacOSComputerInterface+return MacOSComputerInterface(ip_address, api_key=api_key, vm_name=vm_name, api_port=api_port)elif os == "linux":+ from .linux import LinuxComputerInterface+return LinuxComputerInterface(ip_address, api_key=api_key, vm_name=vm_name, api_port=api_port)elif os == "windows":+ from .windows import WindowsComputerInterface+return WindowsComputerInterface(ip_address, api_key=api_key, vm_name=vm_name, api_port=api_port)+ elif os == "android":+ from .android import AndroidComputerInterface++ return AndroidComputerInterface(+ ip_address, api_key=api_key, vm_name=vm_name, api_port=api_port+ )else:raise ValueError(f"Unsupported OS type: {os}")diff --git a/libs/python/computer/computer/providers/winsandbox/setup_script.ps1 b/libs/python/computer/computer/providers/winsandbox/setup_script.ps1index 8a0d4d63c3..34e285bb95 100644--- a/libs/python/computer/computer/providers/winsandbox/setup_script.ps1+++ b/libs/python/computer/computer/providers/winsandbox/setup_script.ps1@@ -79,13 +79,23 @@ try {$pythonVersion = & $pythonExe --version 2>&1Write-Host "Python version: $pythonVersion"- # Step 2: Create a dedicated virtual environment in mapped Desktop folder (persistent)- Write-Host "Step 2: Creating virtual environment (if needed)..."+ # Step 2: Install UV package manager (standalone, before creating venv)+ Write-Host "Step 2: Installing UV package manager..."+ try {+ powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"+ Write-Host "UV installed successfully"+ } catch {+ Write-Host "UV install warning: $($_.Exception.Message)"+ throw "Failed to install UV"+ }++ # Step 3: Create virtual environment using UV+ Write-Host "Step 3: Creating virtual environment with UV (if needed)..."$cachePath = "C:\Users\WDAGUtilityAccount\Desktop\wsb_cache"$venvPath = "C:\Users\WDAGUtilityAccount\Desktop\wsb_cache\venv"if (!(Test-Path $venvPath)) {- Write-Host "Creating venv at: $venvPath"- & $pythonExe -m venv $venvPath+ Write-Host "Creating venv with UV at: $venvPath"+ uv venv $venvPath} else {Write-Host "Venv already exists at: $venvPath"}@@ -104,19 +114,13 @@ try {}Write-Host "Using venv Python: $venvPython"- # Step 3: Install cua-computer-server into the venv- Write-Host "Step 3: Installing cua-computer-server..."-- Write-Host "Upgrading pip..."- & $venvPython -m pip install --upgrade pip --quiet-- Write-Host "Installing cua-computer-server..."- & $venvPython -m pip install cua-computer-server-+ # Step 4: Install cua-computer-server using UV+ Write-Host "Step 4: Installing cua-computer-server with UV..."+ uv pip install --project $venvPath cua-computer-serverWrite-Host "cua-computer-server installation completed."- # Step 4: Start computer server in background using the venv Python- Write-Host "Step 4: Starting computer server in background..."+ # Step 5: Start computer server in background using the venv Python+ Write-Host "Step 5: Starting computer server in background..."Write-Host "Starting computer server with: $venvPython"# Start the computer server in the backgrounddiff --git a/libs/qemu-docker/android/Dockerfile b/libs/qemu-docker/android/Dockerfileindex c5168475d5..6b15834d87 100644--- a/libs/qemu-docker/android/Dockerfile+++ b/libs/qemu-docker/android/Dockerfile@@ -42,26 +42,42 @@ COPY --from=builder /build/wallpaper-manager/app/build/outputs/apk/debug/app-debRUN apt-get update && \apt-get install -y \- python3 \- python3-pip \- python3-venv \- python3-dev \- python3-tk \+ software-properties-common \build-essential \curl \+ gcc \+ && add-apt-repository -y ppa:deadsnakes/ppa && \+ apt-get update && \+ apt-get install -y \+ python3.12 \+ python3.12-venv \+ python3.12-dev \+ python3.12-tk \&& rm -rf /var/lib/apt/lists/*-RUN python3 -m venv /opt/venv-ENV PATH="/opt/venv/bin:$PATH"+# Install UV package manager+RUN curl -LsSf https://astral.sh/uv/install.sh | sh && \+ chmod 755 /root /root/.local /root/.local/bin /root/.local/bin/uv && \+ ln -sf /root/.local/bin/uv /usr/local/bin/uv && \+ uv --version++# Set Python 3.12 as default python3+RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1 && \+ update-alternatives --set python3 /usr/bin/python3.12-RUN /opt/venv/bin/pip install --no-cache-dir --upgrade pip && \- /opt/venv/bin/pip install --no-cache-dir cua-computer-server+# Create UV project for cua-computer-server+RUN mkdir -p /opt/cua-server && \+ uv init --vcs none --no-readme --no-workspace --no-pin-python /opt/cua-server && \+ uv add --directory /opt/cua-server cua-computer-serverCOPY src/entry.sh /usr/local/bin/entry.shRUN chmod +x /usr/local/bin/entry.sh-# Make venv accessible to androidusr-RUN chown -R 1300:1301 /opt/venv+# Make UV project accessible to androidusr+RUN chown -R 1300:1301 /opt/cua-server++# Ensure UV is accessible in PATH for androidusr+ENV PATH="/usr/local/bin:$PATH"EXPOSE 8000diff --git a/libs/qemu-docker/android/dev.Dockerfile b/libs/qemu-docker/android/dev.Dockerfileindex f33e3fd0d9..c2ddbb73c2 100644--- a/libs/qemu-docker/android/dev.Dockerfile+++ b/libs/qemu-docker/android/dev.Dockerfile@@ -47,29 +47,45 @@ COPY --from=builder /build/wallpaper-manager/app/build/outputs/apk/debug/app-debRUN apt-get update && \apt-get install -y \- python3 \- python3-pip \- python3-venv \- python3-dev \- python3-tk \+ software-properties-common \build-essential \curl \+ gcc \+ && add-apt-repository -y ppa:deadsnakes/ppa && \+ apt-get update && \+ apt-get install -y \+ python3.12 \+ python3.12-venv \+ python3.12-dev \+ python3.12-tk \&& rm -rf /var/lib/apt/lists/*-RUN python3 -m venv /opt/venv-ENV PATH="/opt/venv/bin:$PATH"+# Install UV package manager+RUN curl -LsSf https://astral.sh/uv/install.sh | sh && \+ chmod 755 /root /root/.local /root/.local/bin /root/.local/bin/uv && \+ ln -sf /root/.local/bin/uv /usr/local/bin/uv && \+ uv --version++# Set Python 3.12 as default python3+RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1 && \+ update-alternatives --set python3 /usr/bin/python3.12-# Install computer-server from local source for development+# Create UV project for cua-computer-server+RUN mkdir -p /opt/cua-server && \+ uv init --vcs none --no-readme --no-workspace --no-pin-python /opt/cua-server++# Install computer-server from local source for development (editable mode)COPY python/computer-server /tmp/computer-server-WORKDIR /tmp/computer-server-RUN /opt/venv/bin/pip install --no-cache-dir --upgrade pip && \- /opt/venv/bin/pip install --no-cache-dir -e .+RUN uv add --directory /opt/cua-server --editable /tmp/computer-serverCOPY qemu-docker/android/src/entry.sh /usr/local/bin/entry.shRUN chmod +x /usr/local/bin/entry.sh-# Make venv accessible to androidusr-RUN chown -R 1300:1301 /opt/venv+# Make UV project accessible to androidusr+RUN chown -R 1300:1301 /opt/cua-server++# Ensure UV is accessible in PATH for androidusr+ENV PATH="/usr/local/bin:$PATH"EXPOSE 8000diff --git a/libs/qemu-docker/android/src/entry.sh b/libs/qemu-docker/android/src/entry.shindex 15c1ec0f0a..7282707a1a 100644--- a/libs/qemu-docker/android/src/entry.sh+++ b/libs/qemu-docker/android/src/entry.sh@@ -1,10 +1,23 @@#!/usr/bin/env bashset -Eeuo pipefail+# Ensure UV is in PATH+export PATH="/usr/local/bin:$PATH"+info () { printf "%b%s%b" "\E[1;34m❯ \E[1;36m" "${1:-}" "\E[0m\n"; }error () { printf "%b%s%b" "\E[1;31m❯ " "ERROR: ${1:-}" "\E[0m\n" >&2; }warn () { printf "%b%s%b" "\E[1;31m❯ " "Warning: ${1:-}" "\E[0m\n" >&2; }+# Kill any existing ADB server and emulator processes+info "Cleaning up any existing ADB/emulator processes..."+adb kill-server 2>/dev/null || true+pkill -f "qemu-system" 2>/dev/null || true+sleep 2++# Start ADB server+info "Starting ADB server..."+adb start-server+# Start the original docker-android entrypoint in background# This handles emulator startup, VNC, noVNC, etc.info "Starting \"${EMULATOR_DEVICE}\" emulator..."@@ -13,27 +26,44 @@ info "Starting \"${EMULATOR_DEVICE}\" emulator..."# Wait for ADB device to appear and boot to completeinfo "Waiting for emulator to be ready..."counter=0-timeout=300+timeout=600while [ $counter -lt $timeout ]; do- if adb devices 2>/dev/null | grep -q "emulator"; then+ # Check if emulator device is listed+ emulator_found=$(adb devices 2>/dev/null | grep -c "emulator" 2>/dev/null || echo "0")+ # Strip whitespace and ensure it's a valid integer+ emulator_found=$(echo "$emulator_found" | tr -d '\n\r' | tr -d ' ')+ # Default to 0 if empty or not a number+ if ! [[ "$emulator_found" =~ ^[0-9]+$ ]]; then+ emulator_found=0+ fi+ if [ "$emulator_found" -gt 0 ]; then# Check if boot is completeboot_completed=$(adb shell getprop sys.boot_completed 2>&1 | tr -d '\r\n' | grep -o "1" || echo "0")if [ "$boot_completed" = "1" ]; theninfo "✓ Emulator \"${EMULATOR_DEVICE}\" is ready!"break+ else+ # Show what we're waiting for+ if [ $((counter % 20)) -eq 0 ]; then+ info " Emulator detected, waiting for boot to complete... ($counter/$timeout seconds)"+ fi+ fi+ else+ # Show that we're still waiting for device+ if [ $((counter % 20)) -eq 0 ]; then+ info " Waiting for emulator device... ($counter/$timeout seconds)"fifisleep 2counter=$((counter + 2))-- # Show progress every 10 seconds- if [ $((counter % 10)) -eq 0 ]; then- info " Still waiting... ($counter/$timeout seconds)"- fidoneif [ $counter -ge $timeout ]; thenerror "✗ Emulator \"${EMULATOR_DEVICE}\" failed to start within $timeout seconds"+ info "ADB devices:"+ adb devices+ info "Emulator processes:"+ ps aux | grep qemu || echo "No qemu processes found"exit 1fi@@ -52,5 +82,4 @@ elsefiinfo "Starting Computer Server..."-source /opt/venv/bin/activate-DISPLAY= python -m computer_server --host 0.0.0.0 --port 8000 --log-level info+DISPLAY= uv run --directory /opt/cua-server python -m computer_server --host 0.0.0.0 --port 8000 --log-level infodiff --git a/libs/qemu-docker/linux/src/vm/setup/setup-cua-server.sh b/libs/qemu-docker/linux/src/vm/setup/setup-cua-server.shindex 217ff29b2c..31fb80a8bd 100644--- a/libs/qemu-docker/linux/src/vm/setup/setup-cua-server.sh+++ b/libs/qemu-docker/linux/src/vm/setup/setup-cua-server.sh@@ -7,8 +7,7 @@ set -eUSER_NAME="docker"USER_HOME="/home/$USER_NAME"SCRIPT_DIR="/opt/oem"-CUA_DIR="/opt/cua-server"-VENV_DIR="$CUA_DIR/venv"+PROJECT_DIR="/opt/cua-server"SERVICE_NAME="cua-computer-server"LOG_FILE="$SCRIPT_DIR/setup.log"@@ -18,32 +17,102 @@ log() {log "=== Installing Cua Computer Server ==="-# Install Python 3 and venv-log "Installing Python 3 and dependencies..."-sudo apt-get install -y python3 python3-venv python3-pip python3-tk python3-dev gnome-screenshot+# Install Python 3.12 and dependencies+log "Installing Python 3.12 and dependencies..."+sudo apt-get update+sudo apt-get install -y software-properties-common gnome-screenshot curl+sudo add-apt-repository -y ppa:deadsnakes/ppa+sudo apt-get update+sudo apt-get install -y python3.12 python3.12-venv python3.12-tk python3.12-dev build-essential linux-headers-$(uname -r) gcc++# Wait for network to be ready+log "Checking network connectivity..."+NETWORK_RETRIES=30+NETWORK_DELAY=2+NETWORK_READY=false++for i in $(seq 1 $NETWORK_RETRIES); do+ if curl -s --connect-timeout 3 https://astral.sh > /dev/null 2>&1; then+ log "Network is ready"+ NETWORK_READY=true+ break+ fi+ if [ $i -lt $NETWORK_RETRIES ]; then+ log "Network not ready, waiting... (attempt $i/$NETWORK_RETRIES)"+ sleep $NETWORK_DELAY+ fi+done-# Create Cua directory-log "Creating Cua directory at $CUA_DIR..."-sudo mkdir -p "$CUA_DIR"-sudo chown "$USER_NAME:$USER_NAME" "$CUA_DIR"+if [ "$NETWORK_READY" = false ]; then+ log "Network failed to become ready after $NETWORK_RETRIES attempts"+ exit 1+fi-# Create virtual environment-if [ -f "$VENV_DIR/bin/python" ]; then- log "Existing venv detected; skipping creation"-else- log "Creating Python virtual environment at $VENV_DIR..."- python3 -m venv "$VENV_DIR"- log "Virtual environment created successfully"+# Install UV package manager as the service user (with retry logic)+log "Installing UV package manager for user $USER_NAME..."+MAX_RETRIES=3+RETRY_DELAY=5+UV_INSTALLED=false++for i in $(seq 1 $MAX_RETRIES); do+ log "UV installation attempt $i of $MAX_RETRIES"+ if sudo -u "$USER_NAME" bash -c "curl -LsSf https://astral.sh/uv/install.sh | sh"; then+ UV_PATH="$USER_HOME/.local/bin/uv"+ if [ -f "$UV_PATH" ]; then+ log "UV installed successfully at $UV_PATH"+ UV_INSTALLED=true+ break+ fi+ fi+ if [ $i -lt $MAX_RETRIES ]; then+ log "UV install attempt $i failed. Retrying in $RETRY_DELAY seconds..."+ sleep $RETRY_DELAY+ RETRY_DELAY=$((RETRY_DELAY * 2))+ fi+done++if [ "$UV_INSTALLED" = false ]; then+ log "UV installation failed after $MAX_RETRIES attempts"+ exit 1fi-# Activate and install packages-log "Upgrading pip, setuptools, and wheel..."-"$VENV_DIR/bin/pip" install --upgrade pip setuptools wheel+# Add UV to PATH for subsequent commands in this script+export PATH="$USER_HOME/.local/bin:$PATH"++# Create system-wide symlink for UV so it's available as 'uv' command+log "Creating system-wide symlink for UV..."+sudo ln -sf "$USER_HOME/.local/bin/uv" /usr/local/bin/uv+log "UV is now available system-wide"+# Set Python 3.12 as default python3 (after all apt operations are complete)+log "Setting Python 3.12 as default python3..."+sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1+sudo update-alternatives --set python3 /usr/bin/python3.12++# Create UV project directory+log "Creating UV project at $PROJECT_DIR..."+sudo mkdir -p "$PROJECT_DIR"+sudo chown "$USER_NAME:$USER_NAME" "$PROJECT_DIR"++PROJECT_FILE="$PROJECT_DIR/pyproject.toml"+if [ -f "$PROJECT_FILE" ]; then+ log "Existing UV project detected; skipping creation"+else+ log "Creating UV project..."+ sudo -u "$USER_NAME" uv init --vcs none --no-readme --no-workspace --no-pin-python "$PROJECT_DIR"+ log "UV project created successfully"+fi++# Install packages using UV as the service userlog "Installing cua-computer-server..."-"$VENV_DIR/bin/pip" install --upgrade cua-computer-server "Pillow>=9.2.0"+sudo -u "$USER_NAME" uv add --directory "$PROJECT_DIR" cua-computer-server "Pillow>=9.2.0"log "cua-computer-server installed successfully"+log "Installing playwright & firefox browser..."+sudo -u "$USER_NAME" uv add --directory "$PROJECT_DIR" playwright+sudo -u "$USER_NAME" uv run --directory "$PROJECT_DIR" playwright install firefox+log "playwright installed successfully"+# Open firewall for port 5000 (if ufw is available)if command -v ufw &> /dev/null; thenlog "Opening firewall for port 5000..."@@ -52,23 +121,22 @@ if command -v ufw &> /dev/null; thenfi# Create start script with auto-restart-START_SCRIPT="$CUA_DIR/start-server.sh"+START_SCRIPT="$PROJECT_DIR/start-server.sh"log "Creating start script at $START_SCRIPT..."cat > "$START_SCRIPT" << 'EOF'#!/bin/bash# Cua Computer Server Start Script with auto-restart-CUA_DIR="/opt/cua-server"-VENV_DIR="$CUA_DIR/venv"-LOG_FILE="$CUA_DIR/server.log"+PROJECT_DIR="/opt/cua-server"+LOG_FILE="$PROJECT_DIR/server.log"start_server() {echo "$(date '+%Y-%m-%d %H:%M:%S') Updating cua-computer-server..." >> "$LOG_FILE"- "$VENV_DIR/bin/pip" install --upgrade cua-computer-server >> "$LOG_FILE" 2>&1+ uv add --directory "$PROJECT_DIR" cua-computer-server >> "$LOG_FILE" 2>&1echo "$(date '+%Y-%m-%d %H:%M:%S') Starting Cua Computer Server on port 5000..." >> "$LOG_FILE"- "$VENV_DIR/bin/python" -m computer_server --port 5000 >> "$LOG_FILE" 2>&1+ uv run --directory "$PROJECT_DIR" python -m computer_server --port 5000 >> "$LOG_FILE" 2>&1return $?}@@ -111,7 +179,7 @@ Environment=PYTHONUNBUFFERED=1Environment=DISPLAY=:0Environment=XAUTHORITY=$USER_HOME/.XauthorityUser=$USER_NAME-WorkingDirectory=$CUA_DIR+WorkingDirectory=$PROJECT_DIR[Install]WantedBy=graphical.target@@ -119,9 +187,9 @@ EOFlog "Systemd service created at /etc/systemd/system/$SERVICE_NAME.service"-# Ensure proper ownership of Cua directory-log "Setting ownership of $CUA_DIR to $USER_NAME..."-sudo chown -R "$USER_NAME:$USER_NAME" "$CUA_DIR"+# Ensure proper ownership of project directory+log "Setting ownership of $PROJECT_DIR to $USER_NAME..."+sudo chown -R "$USER_NAME:$USER_NAME" "$PROJECT_DIR"# Enable and start the servicelog "Enabling systemd service..."diff --git a/libs/qemu-docker/windows/src/vm/setup/setup-cua-server.ps1 b/libs/qemu-docker/windows/src/vm/setup/setup-cua-server.ps1index 276454a0f2..f5a9c8dcda 100644--- a/libs/qemu-docker/windows/src/vm/setup/setup-cua-server.ps1+++ b/libs/qemu-docker/windows/src/vm/setup/setup-cua-server.ps1@@ -33,49 +33,84 @@ try {Write-Log -LogFile $script:LogFile -Message "Chocolatey bootstrap warning: $($_.Exception.Message)"}-# Create venv-$HomeDir = $env:USERPROFILE-$CuaDir = Join-Path $HomeDir '.cua-server'-$VenvDir = Join-Path $CuaDir 'venv'-New-Item -ItemType Directory -Force -Path $CuaDir | Out-Null--Write-Log -LogFile $script:LogFile -Message "Creating Python virtual environment at $VenvDir"-$ExistingVenvPython = Join-Path $VenvDir 'Scripts\python.exe'-if (Test-Path -LiteralPath $ExistingVenvPython) {- Write-Log -LogFile $script:LogFile -Message "Existing venv detected; skipping creation"-} else {+# Install UV package manager first (with retry logic)+Write-Log -LogFile $script:LogFile -Message "Installing UV package manager"+$maxRetries = 3+$retryDelay = 5+$uvInstalled = $false++for ($i = 1; $i -le $maxRetries; $i++) {try {- & py -m venv $VenvDir- Write-Log -LogFile $script:LogFile -Message "Virtual environment created successfully"+ Write-Log -LogFile $script:LogFile -Message "UV installation attempt $i of $maxRetries"+ # Install UV using the official standalone installer+ powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" 2>&1 | Tee-Object -FilePath $script:LogFile -Append | Out-Null++ # Add UV to PATH for current session+ $uvPath = Join-Path $env:USERPROFILE ".local\bin"+ if (Test-Path $uvPath) {+ $env:Path = "$uvPath;$env:Path"+ Write-Log -LogFile $script:LogFile -Message "UV installed successfully and added to PATH"+ $uvInstalled = $true+ break+ } else {+ Write-Log -LogFile $script:LogFile -Message "UV installed but path not found at $uvPath"+ $uvInstalled = $true+ break+ }} catch {- Write-Log -LogFile $script:LogFile -Message "venv creation error: $($_.Exception.Message)"- throw+ Write-Log -LogFile $script:LogFile -Message "UV install attempt $i failed: $($_.Exception.Message)"+ if ($i -lt $maxRetries) {+ Write-Log -LogFile $script:LogFile -Message "Retrying in $retryDelay seconds..."+ Start-Sleep -Seconds $retryDelay+ $retryDelay = $retryDelay * 2 # Exponential backoff+ }}}-$PyExe = Join-Path $VenvDir 'Scripts\python.exe'-$PipExe = Join-Path $VenvDir 'Scripts\pip.exe'-$ActivateScript = Join-Path $VenvDir 'Scripts\Activate.ps1'+if (-not $uvInstalled) {+ Write-Log -LogFile $script:LogFile -Message "UV installation failed after $maxRetries attempts"+ throw "Failed to install UV package manager"+}-Write-Log -LogFile $script:LogFile -Message "Activating virtual environment"-& $ActivateScript+# Create UV project directory+$HomeDir = $env:USERPROFILE+$ProjectDir = Join-Path $HomeDir 'cua-server'-Write-Log -LogFile $script:LogFile -Message "Upgrading pip, setuptools, and wheel"-try {- & $PipExe install --upgrade pip setuptools wheel 2>&1 | Tee-Object -FilePath $script:LogFile -Append | Out-Null-} catch {- Write-Log -LogFile $script:LogFile -Message "pip bootstrap warning: $($_.Exception.Message)"+Write-Log -LogFile $script:LogFile -Message "Creating UV project at $ProjectDir"+$ProjectFile = Join-Path $ProjectDir 'pyproject.toml'+if (Test-Path -LiteralPath $ProjectFile) {+ Write-Log -LogFile $script:LogFile -Message "Existing UV project detected; skipping creation"+} else {+ try {+ # Create parent directory if it doesn't exist+ New-Item -ItemType Directory -Force -Path $ProjectDir | Out-Null+ & uv init --vcs none --no-readme --no-workspace --no-pin-python $ProjectDir 2>&1 | Tee-Object -FilePath $script:LogFile -Append | Out-Null+ Write-Log -LogFile $script:LogFile -Message "UV project created successfully"+ } catch {+ Write-Log -LogFile $script:LogFile -Message "UV project creation error: $($_.Exception.Message)"+ throw+ }}Write-Log -LogFile $script:LogFile -Message "Installing cua-computer-server"try {- & $PipExe install --upgrade cua-computer-server 2>&1 | Tee-Object -FilePath $script:LogFile -Append | Out-Null+ & uv add --directory $ProjectDir cua-computer-server 2>&1 | Tee-Object -FilePath $script:LogFile -Append | Out-NullWrite-Log -LogFile $script:LogFile -Message "cua-computer-server installed successfully"} catch {Write-Log -LogFile $script:LogFile -Message "Server install error: $($_.Exception.Message)"throw}+Write-Log -LogFile $script:LogFile -Message "Installing playwright & firefox browser"+try {+ & uv add --directory $ProjectDir playwright 2>&1 | Tee-Object -FilePath $script:LogFile -Append | Out-Null+ & uv run --directory $ProjectDir playwright install firefox 2>&1 | Tee-Object -FilePath $script:LogFile -Append | Out-Null+ Write-Log -LogFile $script:LogFile -Message "playwright installed successfully"+} catch {+ Write-Log -LogFile $script:LogFile -Message "Playwright install error: $($_.Exception.Message)"+ throw+}+# Open firewall for port 5000Write-Log -LogFile $script:LogFile -Message "Opening firewall for port 5000"try {@@ -86,24 +121,27 @@ try {}# Create start script with auto-restart-$StartScript = Join-Path $CuaDir 'start-server.ps1'+$StartScript = Join-Path $ProjectDir 'start-server.ps1'$StartScriptContent = @"param()`$env:PYTHONUNBUFFERED = '1'-`$LogFile = Join-Path '$CuaDir' 'server.log'-`$ActivateScript = '$ActivateScript'-`$PipExe = '$PipExe'-`$Python = '$PyExe'+# Ensure UV is in PATH+`$uvPath = Join-Path `$env:USERPROFILE '.local\bin'+if (Test-Path `$uvPath) {+ `$env:Path = "`$uvPath;`$env:Path"+}++`$ProjectDir = '$ProjectDir'+`$LogFile = Join-Path `$ProjectDir 'server.log'function Start-Server {- Write-Output "Activating virtual environment and updating cua-computer-server..." | Out-File -FilePath `$LogFile -Append- & `$ActivateScript- & `$PipExe install --upgrade cua-computer-server 2>&1 | Out-File -FilePath `$LogFile -Append+ Write-Output "Updating cua-computer-server..." | Out-File -FilePath `$LogFile -Append+ & uv add --directory `$ProjectDir cua-computer-server 2>&1 | Out-File -FilePath `$LogFile -AppendWrite-Output "Starting Cua Computer Server on port 5000..." | Out-File -FilePath `$LogFile -Append- & `$Python -m computer_server --port 5000 2>&1 | Out-File -FilePath `$LogFile -Append+ & uv run --directory `$ProjectDir python -m computer_server --port 5000 2>&1 | Out-File -FilePath `$LogFile -Appendreturn `$LASTEXITCODE}@@ -119,7 +157,7 @@ Set-Content -Path $StartScript -Value $StartScriptContent -Encoding UTF8Write-Log -LogFile $script:LogFile -Message "Start script created at $StartScript"# Create VBScript wrapper to launch PowerShell hidden-$VbsWrapper = Join-Path $CuaDir 'start-server-hidden.vbs'+$VbsWrapper = Join-Path $ProjectDir 'start-server-hidden.vbs'$VbsContent = @"Set objShell = CreateObject("WScript.Shell")objShell.Run "powershell.exe -NoProfile -ExecutionPolicy Bypass -File ""$StartScript""", 0, Falsediff --git a/libs/xfce/Dockerfile b/libs/xfce/Dockerfileindex 1c46cf7a17..1253c5abb1 100644--- a/libs/xfce/Dockerfile+++ b/libs/xfce/Dockerfile@@ -80,6 +80,7 @@ RUN add-apt-repository -y ppa:deadsnakes/ppa && \&& \python3.12 -m ensurepip --upgrade && \python3.12 -m pip install --upgrade pip setuptools wheel && \+ python3.12 -m pip install uv && \rm -rf /var/lib/apt/lists/*# Ensure 'python' points to Python 3.12@@ -120,8 +121,8 @@ RUN git clone https://github.com/trycua/noVNC.git /opt/noVNC && \RUN mkdir -p /home/cua/.cache && \chown -R cua:cua /home/cua/.cache-# Install computer-server using Python 3.12 pip-RUN python3.12 -m pip install cua-computer-server+# Install computer-server+RUN uv pip install --system cua-computer-server# Install GTK and WebKit dependencies for pywebviewRUN apt-get update && apt-get install -y \@@ -136,11 +137,11 @@ RUN apt-get update && apt-get install -y \&& rm -rf /var/lib/apt/lists/*# Install pywebview with GTK backend, used by cua-bench for web UIs-RUN python3.12 -m pip install "pywebview[gtk]"-RUN python3.12 -m pip install cua-bench-ui>=0.7.0 --no-cache-dir+RUN uv pip install --system "pywebview[gtk]"+RUN uv pip install --system cua-bench-ui>=0.7.0 --no-cache-dir# Install playwright and Firefox dependencies-RUN python3.12 -m pip install playwright && \+RUN uv pip install --system playwright && \python3.12 -m playwright install --with-deps firefox# Fix any cache files created by pipdiff --git a/libs/xfce/Dockerfile.dev b/libs/xfce/Dockerfile.devindex 9b34441bc1..8d2d77b8a1 100644--- a/libs/xfce/Dockerfile.dev+++ b/libs/xfce/Dockerfile.dev@@ -79,6 +79,7 @@ RUN add-apt-repository -y ppa:deadsnakes/ppa && \python3.12 python3.12-venv python3.12-dev python3.12-tk && \python3.12 -m ensurepip --upgrade && \python3.12 -m pip install --upgrade pip setuptools wheel && \+ python3.12 -m pip install uv && \rm -rf /var/lib/apt/lists/*# Ensure 'python' points to Python 3.12@@ -121,7 +122,7 @@ RUN mkdir -p /home/cua/.cache && \# Copy local computer-server source and install itCOPY python/computer-server /tmp/computer-server-RUN python3.12 -m pip install /tmp/computer-server && \+RUN uv pip install --system /tmp/computer-server && \rm -rf /tmp/computer-server# Install GTK and WebKit dependencies for pywebview@@ -137,11 +138,11 @@ RUN apt-get update && apt-get install -y \&& rm -rf /var/lib/apt/lists/*# Install pywebview with GTK backend, used by cua-bench for web UIs-RUN python3.12 -m pip install "pywebview[gtk]"-RUN python3.12 -m pip install cua-bench-ui>=0.7.0 --no-cache-dir+RUN uv pip install --system "pywebview[gtk]"+RUN uv pip install --system cua-bench-ui>=0.7.0 --no-cache-dir# Install playwright and Firefox dependencies-RUN python3.12 -m pip install playwright && \+RUN uv pip install --system playwright && \python3.12 -m playwright install --with-deps firefox# Fix any cache files created by pip