From 383c13b695ab16641ca3d214719bef91058b52c2 Mon Sep 17 00:00:00 2001
From: Luca Steingen <33423679+LucaStngn@users.noreply.github.com>
Date: Thu, 11 Dec 2025 20:54:06 -0800
Subject: [PATCH 1/4] Refactor Python quickstart examples to use asyncio
Updated all Python code examples in the quickstart and agent sections to use explicit async main functions and asyncio.run(). This improves clarity for asynchronous usage, ensures proper connection and disconnection of resources, and aligns with best practices for async Python code.
---
docs/content/docs/get-started/quickstart.mdx | 168 +++++++++++++++----
1 file changed, 131 insertions(+), 37 deletions(-)
diff --git a/docs/content/docs/get-started/quickstart.mdx b/docs/content/docs/get-started/quickstart.mdx
index 86874f22..c81f611f 100644
--- a/docs/content/docs/get-started/quickstart.mdx
+++ b/docs/content/docs/get-started/quickstart.mdx
@@ -147,6 +147,7 @@ Connect to your Cua computer and perform basic interactions, such as taking scre
```python
import os
from computer import Computer
+ import asyncio
os.environ["CUA_API_KEY"] = "sk_cua-api01_..."
@@ -155,42 +156,101 @@ Connect to your Cua computer and perform basic interactions, such as taking scre
provider_type="cloud",
name="your-sandbox-name" # from CLI or website
)
- await computer.run() # Connect to the sandbox
+
+ async def main():
+ await computer.run() # Connect to the sandbox
+
+ try:
+ # Take a screenshot of the computer's current display
+ screenshot = await computer.interface.screenshot()
+ # Simulate a left-click at coordinates (100, 100)
+ await computer.interface.left_click(100, 100)
+ # Type "Hello!" into the active application
+ await computer.interface.type_text("Hello!")
+ finally:
+ await computer.disconnect()
+
+ asyncio.run(main())
```
```python
from computer import Computer
+ import asyncio
computer = Computer(
os_type="linux",
provider_type="docker",
image="trycua/cua-xfce:latest" # or "trycua/cua-ubuntu:latest"
)
- await computer.run() # Launch & connect to the sandbox
+
+ async def main():
+ await computer.run() # Launch & connect to the sandbox
+
+ try:
+ # Take a screenshot of the computer's current display
+ screenshot = await computer.interface.screenshot()
+ # Simulate a left-click at coordinates (100, 100)
+ await computer.interface.left_click(100, 100)
+ # Type "Hello!" into the active application
+ await computer.interface.type_text("Hello!")
+ finally:
+ await computer.disconnect()
+
+ asyncio.run(main())
```
```python
from computer import Computer
+ import asyncio
computer = Computer(
os_type="macos",
provider_type="lume",
name="macos-sequoia-cua:latest"
)
- await computer.run() # Launch & connect to the sandbox
+
+ async def main():
+ await computer.run() # Launch & connect to the sandbox
+
+ try:
+ # Take a screenshot of the computer's current display
+ screenshot = await computer.interface.screenshot()
+ # Simulate a left-click at coordinates (100, 100)
+ await computer.interface.left_click(100, 100)
+ # Type "Hello!" into the active application
+ await computer.interface.type_text("Hello!")
+ finally:
+ await computer.disconnect()
+
+ asyncio.run(main())
```
```python
from computer import Computer
+ import asyncio
computer = Computer(
os_type="windows",
provider_type="windows_sandbox"
)
- await computer.run() # Launch & connect to the sandbox
+
+ async def main():
+ await computer.run() # Launch & connect to the sandbox
+
+ try:
+ # Take a screenshot of the computer's current display
+ screenshot = await computer.interface.screenshot()
+ # Simulate a left-click at coordinates (100, 100)
+ await computer.interface.left_click(100, 100)
+ # Type "Hello!" into the active application
+ await computer.interface.type_text("Hello!")
+ finally:
+ await computer.disconnect()
+
+ asyncio.run(main())
```
@@ -203,26 +263,28 @@ Connect to your Cua computer and perform basic interactions, such as taking scre
Then, use the `Computer` object to connect:
```python
from computer import Computer
+ import asyncio
computer = Computer(use_host_computer_server=True)
- await computer.run() # Connect to the host desktop
+
+ async def main():
+ await computer.run() # Connect to the host desktop
+
+ try:
+ # Take a screenshot of the computer's current display
+ screenshot = await computer.interface.screenshot()
+ # Simulate a left-click at coordinates (100, 100)
+ await computer.interface.left_click(100, 100)
+ # Type "Hello!" into the active application
+ await computer.interface.type_text("Hello!")
+ finally:
+ await computer.disconnect()
+
+ asyncio.run(main())
```
- Once connected, you can perform interactions:
- ```python
- try:
- # Take a screenshot of the computer's current display
- screenshot = await computer.interface.screenshot()
- # Simulate a left-click at coordinates (100, 100)
- await computer.interface.left_click(100, 100)
- # Type "Hello!" into the active application
- await computer.interface.type_text("Hello!")
- finally:
- await computer.close()
- ```
-
@@ -316,7 +378,7 @@ Connect to your Cua computer and perform basic interactions, such as taking scre
// Type "Hello!" into the active application
await computer.interface.typeText("Hello!");
} finally {
- await computer.close();
+ await computer.disconnect();
}
```
@@ -349,22 +411,38 @@ Choose how you want to access vision-language models for your agent:
**Use the agent with CUA models:**
```python
import os
+ import asyncio
+ from computer import Computer
from agent import ComputerAgent
os.environ["CUA_API_KEY"] = "sk_cua-api01_..."
- agent = ComputerAgent(
- model="cua/anthropic/claude-sonnet-4.5", # CUA-routed model
- tools=[computer],
- max_trajectory_budget=5.0
+ computer = Computer(
+ os_type="linux", # or "windows" or "macos"
+ provider_type="cloud",
+ name="your-sandbox-name" # from CLI or website
)
- messages = [{"role": "user", "content": "Take a screenshot and tell me what you see"}]
+ async def main():
+ await computer.run() # Connect to the sandbox
- async for result in agent.run(messages):
- for item in result["output"]:
- if item["type"] == "message":
- print(item["content"][0]["text"])
+ try:
+ agent = ComputerAgent(
+ model="cua/anthropic/claude-sonnet-4.5", # CUA-routed model
+ tools=[computer],
+ max_trajectory_budget=5.0
+ )
+
+ messages = [{"role": "user", "content": "Take a screenshot and tell me what you see"}]
+
+ async for result in agent.run(messages):
+ for item in result["output"]:
+ if item["type"] == "message":
+ print(item["content"][0]["text"])
+ finally:
+ await computer.disconnect()
+
+ asyncio.run(main())
```
**Available CUA models:**
@@ -386,6 +464,8 @@ Choose how you want to access vision-language models for your agent:
**Use the agent with your provider:**
```python
import os
+ import asyncio
+ from computer import Computer
from agent import ComputerAgent
# Set your provider API key
@@ -393,18 +473,32 @@ Choose how you want to access vision-language models for your agent:
# OR
os.environ["OPENAI_API_KEY"] = "sk-..." # For OpenAI
- agent = ComputerAgent(
- model="anthropic/claude-sonnet-4-5-20250929", # Direct provider model
- tools=[computer],
- max_trajectory_budget=5.0
+ computer = Computer(
+ os_type="linux", # or "windows" or "macos"
+ provider_type="docker",
+ image="trycua/cua-xfce:latest" # or "trycua/cua-ubuntu:latest"
)
- messages = [{"role": "user", "content": "Take a screenshot and tell me what you see"}]
+ async def main():
+ await computer.run() # Launch & connect to the sandbox
- async for result in agent.run(messages):
- for item in result["output"]:
- if item["type"] == "message":
- print(item["content"][0]["text"])
+ try:
+ agent = ComputerAgent(
+ model="anthropic/claude-sonnet-4-5-20250929", # Direct provider model
+ tools=[computer],
+ max_trajectory_budget=5.0
+ )
+
+ messages = [{"role": "user", "content": "Take a screenshot and tell me what you see"}]
+
+ async for result in agent.run(messages):
+ for item in result["output"]:
+ if item["type"] == "message":
+ print(item["content"][0]["text"])
+ finally:
+ await computer.disconnect()
+
+ asyncio.run(main())
```
**Supported providers:**
From ab34365e819f8d4b45121e190469aecc9dc66c02 Mon Sep 17 00:00:00 2001
From: Sarina Li
Date: Fri, 12 Dec 2025 16:46:49 -0500
Subject: [PATCH 2/4] start stop clarity
---
docs/content/docs/get-started/quickstart.mdx | 28 ++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/docs/content/docs/get-started/quickstart.mdx b/docs/content/docs/get-started/quickstart.mdx
index c81f611f..2d1007fc 100644
--- a/docs/content/docs/get-started/quickstart.mdx
+++ b/docs/content/docs/get-started/quickstart.mdx
@@ -159,6 +159,8 @@ Connect to your Cua computer and perform basic interactions, such as taking scre
async def main():
await computer.run() # Connect to the sandbox
+ # Alternative: If your VM is not running, use start() instead:
+ # await computer.start() # Start and connect to the sandbox
try:
# Take a screenshot of the computer's current display
@@ -169,6 +171,8 @@ Connect to your Cua computer and perform basic interactions, such as taking scre
await computer.interface.type_text("Hello!")
finally:
await computer.disconnect()
+ # Alternative: If you want to fully stop the VM, use stop() instead:
+ # await computer.stop() # Fully stop VM and disconnect
asyncio.run(main())
```
@@ -186,6 +190,8 @@ Connect to your Cua computer and perform basic interactions, such as taking scre
async def main():
await computer.run() # Launch & connect to the sandbox
+ # Alternative: If your VM is not running, use start() instead:
+ # await computer.start() # Start and connect to the sandbox
try:
# Take a screenshot of the computer's current display
@@ -196,6 +202,8 @@ Connect to your Cua computer and perform basic interactions, such as taking scre
await computer.interface.type_text("Hello!")
finally:
await computer.disconnect()
+ # Alternative: If you want to fully stop the VM, use stop() instead:
+ # await computer.stop() # Fully stop VM and disconnect
asyncio.run(main())
```
@@ -213,6 +221,8 @@ Connect to your Cua computer and perform basic interactions, such as taking scre
async def main():
await computer.run() # Launch & connect to the sandbox
+ # Alternative: If your VM is not running, use start() instead:
+ # await computer.start() # Start and connect to the sandbox
try:
# Take a screenshot of the computer's current display
@@ -223,6 +233,8 @@ Connect to your Cua computer and perform basic interactions, such as taking scre
await computer.interface.type_text("Hello!")
finally:
await computer.disconnect()
+ # Alternative: If you want to fully stop the VM, use stop() instead:
+ # await computer.stop() # Fully stop VM and disconnect
asyncio.run(main())
```
@@ -239,6 +251,8 @@ Connect to your Cua computer and perform basic interactions, such as taking scre
async def main():
await computer.run() # Launch & connect to the sandbox
+ # Alternative: If your VM is not running, use start() instead:
+ # await computer.start() # Start and connect to the sandbox
try:
# Take a screenshot of the computer's current display
@@ -249,6 +263,8 @@ Connect to your Cua computer and perform basic interactions, such as taking scre
await computer.interface.type_text("Hello!")
finally:
await computer.disconnect()
+ # Alternative: If you want to fully stop the VM, use stop() instead:
+ # await computer.stop() # Fully stop VM and disconnect
asyncio.run(main())
```
@@ -269,6 +285,8 @@ Connect to your Cua computer and perform basic interactions, such as taking scre
async def main():
await computer.run() # Connect to the host desktop
+ # Alternative: If your computer server is not running, use start() instead:
+ # await computer.start() # Start and connect to the host desktop
try:
# Take a screenshot of the computer's current display
@@ -279,6 +297,8 @@ Connect to your Cua computer and perform basic interactions, such as taking scre
await computer.interface.type_text("Hello!")
finally:
await computer.disconnect()
+ # Alternative: If you want to fully stop everything, use stop() instead:
+ # await computer.stop() # Fully stop and disconnect
asyncio.run(main())
```
@@ -425,6 +445,8 @@ Choose how you want to access vision-language models for your agent:
async def main():
await computer.run() # Connect to the sandbox
+ # Alternative: If your VM is not running, use start() instead:
+ # await computer.start() # Start and connect to the sandbox
try:
agent = ComputerAgent(
@@ -441,6 +463,8 @@ Choose how you want to access vision-language models for your agent:
print(item["content"][0]["text"])
finally:
await computer.disconnect()
+ # Alternative: If you want to fully stop the VM, use stop() instead:
+ # await computer.stop() # Fully stop VM and disconnect
asyncio.run(main())
```
@@ -481,6 +505,8 @@ Choose how you want to access vision-language models for your agent:
async def main():
await computer.run() # Launch & connect to the sandbox
+ # Alternative: If your VM is not running, use start() instead:
+ # await computer.start() # Start and connect to the sandbox
try:
agent = ComputerAgent(
@@ -497,6 +523,8 @@ Choose how you want to access vision-language models for your agent:
print(item["content"][0]["text"])
finally:
await computer.disconnect()
+ # Alternative: If you want to fully stop the VM, use stop() instead:
+ # await computer.stop() # Fully stop VM and disconnect
asyncio.run(main())
```
From 91e9c0e2166027186ca97c941a8464b760004005 Mon Sep 17 00:00:00 2001
From: Sarina Li
Date: Fri, 12 Dec 2025 22:50:53 -0500
Subject: [PATCH 3/4] change to cloud computer
---
docs/content/docs/get-started/quickstart.mdx | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/docs/content/docs/get-started/quickstart.mdx b/docs/content/docs/get-started/quickstart.mdx
index 2d1007fc..80b2e858 100644
--- a/docs/content/docs/get-started/quickstart.mdx
+++ b/docs/content/docs/get-started/quickstart.mdx
@@ -183,9 +183,9 @@ Connect to your Cua computer and perform basic interactions, such as taking scre
import asyncio
computer = Computer(
- os_type="linux",
- provider_type="docker",
- image="trycua/cua-xfce:latest" # or "trycua/cua-ubuntu:latest"
+ os_type="linux", # or "windows" or "macos"
+ provider_type="cloud",
+ name="your-sandbox-name" # from CLI or website
)
async def main():
From 9d5d8ec4e725997ff6d6accb0f23a6bed54fc2e7 Mon Sep 17 00:00:00 2001
From: Sarina Li
Date: Fri, 12 Dec 2025 22:56:35 -0500
Subject: [PATCH 4/4] fix wrong computer
---
docs/content/docs/get-started/quickstart.mdx | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/docs/content/docs/get-started/quickstart.mdx b/docs/content/docs/get-started/quickstart.mdx
index 80b2e858..afb29c03 100644
--- a/docs/content/docs/get-started/quickstart.mdx
+++ b/docs/content/docs/get-started/quickstart.mdx
@@ -183,9 +183,9 @@ Connect to your Cua computer and perform basic interactions, such as taking scre
import asyncio
computer = Computer(
- os_type="linux", # or "windows" or "macos"
- provider_type="cloud",
- name="your-sandbox-name" # from CLI or website
+ os_type="linux",
+ provider_type="docker",
+ image="trycua/cua-xfce:latest" # or "trycua/cua-ubuntu:latest"
)
async def main():
@@ -499,8 +499,8 @@ Choose how you want to access vision-language models for your agent:
computer = Computer(
os_type="linux", # or "windows" or "macos"
- provider_type="docker",
- image="trycua/cua-xfce:latest" # or "trycua/cua-ubuntu:latest"
+ provider_type="cloud",
+ name="your-sandbox-name" # from CLI or website
)
async def main():