# Desktop Sandbox

Desktop Sandbox provides a Linux desktop environment with a graphical user interface (GUI). You can control the mouse, keyboard, and even stream desktop footage via VNC via the SDK. This is useful for Agents that need to perform GUI automation, browser manipulation, or visual tasks.

## Introduction

Desktop Sandbox is located in the `ucloud_sandbox.desktop` module.

```python
from ucloud_sandbox.desktop import Sandbox
```

## Quick start

```python
from ucloud_sandbox.desktop import Sandbox

# Create a Desktop Sandbox instance
#The default resolution is 1024x768
desktop = Sandbox.create()

# Take screenshot
screenshot_bytes = desktop.screenshot()
with open("screenshot.png", "wb") as f:
    f.write(screenshot_bytes)

# Control the mouse
desktop.left_click(100, 200) # Left click at (100, 200)
desktop.write("Hello Desktop!") # Enter text

# Start VNC stream (for real-time viewing)
desktop.stream.start()
print(f"VNC URL: {desktop.stream.get_url()}")

desktop.kill()
```

## Main functions

- **Mouse Control**: `move_mouse`, `left_click`, `right_click`, `double_click`, `drag`, `scroll`.
- **Keyboard Control**: `press`, `write`.
- **Screenshot**: `screenshot` supports returning bytes or streams.
- **VNC Streaming**: The built-in `stream` object (`_VNCServer`) can start the noVNC agent for easy viewing in the browser.
- **Window Management**: Get the current window ID, title, etc. (depends on `xdotool`).

## Notes

- Desktop Sandbox may start slightly slower than standard Sandbox as it requires starting X Server and Desktop Environment (XFCE4).
