Computer SDK v0.3 API Reference

API reference for Computer SDK version 0.3

This is documentation for v0.3. View latest version.

v0.3.7

pip install cua-computer==0.3.7

Cua Computer Interface for cross-platform computer control.

Classes

ClassDescription
ComputerComputer is the main class for interacting with the computer.
VMProviderTypeEnum of supported VM provider types.

Computer

Computer is the main class for interacting with the computer.

Methods

Computer.create_desktop_from_apps

def create_desktop_from_apps(self, apps)

Create a virtual desktop from a list of app names, returning a DioramaComputer that proxies Diorama.Interface but uses diorama_cmds via the computer interface.

Args: apps (list[str]): List of application names to include in the desktop. Returns: DioramaComputer: A proxy object with the Diorama interface, but using diorama_cmds.

Computer.run

async def run(self) -> Optional[str]

Initialize the VM and computer interface.

Computer.disconnect

async def disconnect(self) -> None

Disconnect from the computer's WebSocket interface.

Computer.stop

async def stop(self) -> None

Disconnect from the computer's WebSocket interface and stop the computer.

Computer.get_ip

async def get_ip(self, max_retries: int = 15, retry_delay: int = 3) -> str

Get the IP address of the VM or localhost if using host computer server.

This method delegates to the provider's get_ip method, which waits indefinitely until the VM has a valid IP address.

Args: max_retries: Unused parameter, kept for backward compatibility retry_delay: Delay between retries in seconds (default: 2)

Returns: IP address of the VM or localhost if using host computer server

Computer.wait_vm_ready

async def wait_vm_ready(self) -> Optional[Dict[str, Any]]

Wait for VM to be ready with an IP address.

Returns: VM status information or None if using host computer server.

Computer.update

async def update(self, cpu: Optional[int] = None, memory: Optional[str] = None)

Update VM settings.

Computer.get_screenshot_size

def get_screenshot_size(self, screenshot: bytes) -> Dict[str, int]

Get the dimensions of a screenshot.

Args: screenshot: The screenshot bytes

Returns: Dict[str, int]: Dictionary containing 'width' and 'height' of the image

Computer.to_screen_coordinates

async def to_screen_coordinates(self, x: float, y: float) -> tuple[float, float]

Convert normalized coordinates to screen coordinates.

Args: x: X coordinate between 0 and 1 y: Y coordinate between 0 and 1

Returns: tuple[float, float]: Screen coordinates (x, y)

Computer.to_screenshot_coordinates

async def to_screenshot_coordinates(self, x: float, y: float) -> tuple[float, float]

Convert screen coordinates to screenshot coordinates.

Args: x: X coordinate in screen space y: Y coordinate in screen space

Returns: tuple[float, float]: (x, y) coordinates in screenshot space

Computer.venv_install

async def venv_install(self, venv_name: str, requirements: list[str])

Install packages in a virtual environment.

Args: venv_name: Name of the virtual environment requirements: List of package requirements to install

Returns: Tuple of (stdout, stderr) from the installation command

Computer.venv_cmd

async def venv_cmd(self, venv_name: str, command: str)

Execute a shell command in a virtual environment.

Args: venv_name: Name of the virtual environment command: Shell command to execute in the virtual environment

Returns: Tuple of (stdout, stderr) from the command execution

Computer.venv_exec

async def venv_exec(self, venv_name: str, python_func, args = (), kwargs = {})

Execute Python function in a virtual environment using source code extraction.

Args: venv_name: Name of the virtual environment python_func: A callable function to execute *args: Positional arguments to pass to the function **kwargs: Keyword arguments to pass to the function

Returns: The result of the function execution, or raises any exception that occurred

VMProviderType

Enum of supported VM provider types.

Was this page helpful?