Add Cua Preview

This commit is contained in:
f-trycua
2025-03-16 16:06:32 +01:00
parent 65a851c43b
commit 8baef75e6e
240 changed files with 21368 additions and 424 deletions

229
notebooks/agent_nb.ipynb Normal file
View File

@@ -0,0 +1,229 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Agent\n",
"\n",
"This notebook demonstrates how to use Cua's Agent to run a workflow in a virtual sandbox on Apple Silicon Macs."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Installation"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"zsh:1: no matches found: cua-agent[all]\n"
]
}
],
"source": [
"!pip uninstall cua-agent[all]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install \"cua-agent[all]\"\n",
"\n",
"# Or install individual agent loops:\n",
"# !pip install cua-agent[anthropic]\n",
"# !pip install cua-agent[omni]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# If locally installed, use this instead:\n",
"import os\n",
"\n",
"os.chdir('../libs/agent')\n",
"!poetry install\n",
"!poetry build\n",
"\n",
"!pip uninstall cua-agent -y\n",
"!pip install ./dist/cua_agent-0.1.0-py3-none-any.whl --force-reinstall"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Initialize a Computer Agent"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Computer allows you to run an agentic workflow in a virtual sandbox instances on Apple Silicon. Here's a basic example:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from agent import ComputerAgent, AgenticLoop, LLMProvider\n",
"from computer import Computer"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Similar to Computer, you can either use the async context manager pattern or initialize the ComputerAgent instance directly."
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"# Set your API key\n",
"!export ANTHROPIC_API_KEY=\"your-anthropic-api-key\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Direct initialization:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from datetime import datetime\n",
"import logging\n",
"from pathlib import Path\n",
"\n",
"computer = Computer(verbosity=logging.INFO)\n",
"\n",
"# Create agent with Anthropic loop and provider\n",
"agent = ComputerAgent(\n",
" computer=computer,\n",
" api_key=\"<your-anthropic-api-key>\",\n",
" loop_type=AgenticLoop.ANTHROPIC,\n",
" ai_provider=LLMProvider.ANTHROPIC,\n",
" model='claude-3-7-sonnet-20250219',\n",
" save_trajectory=True,\n",
" trajectory_dir=str(Path(\"trajectories\") / datetime.now().strftime(\"%Y%m%d_%H%M%S\")),\n",
" only_n_most_recent_images=3, # Slightly different from the omni example\n",
" verbosity=logging.INFO,\n",
")\n",
"\n",
"tasks = [\n",
"\"\"\"\n",
"Please help me with the following task:\n",
"1. Open Safari browser\n",
"2. Go to Wikipedia.org\n",
"3. Search for \"Claude AI\" \n",
"4. Summarize the main points you find about Claude AI\n",
"\"\"\"\n",
"]\n",
"\n",
"async with agent:\n",
" for i, task in enumerate(tasks, 1):\n",
" print(f\"\\nExecuting task {i}/{len(tasks)}: {task}\")\n",
" async for result in agent.run(task):\n",
" print(result)\n",
" print(f\"Task {i} completed\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Or using the Omni Agentic Loop:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from datetime import datetime\n",
"import logging\n",
"from pathlib import Path\n",
"\n",
"computer = Computer(verbosity=logging.INFO)\n",
"\n",
"# Create agent with Anthropic loop and provider\n",
"agent = ComputerAgent(\n",
" computer=computer,\n",
" api_key=\"<your-anthropic-api-key>\",\n",
" loop_type=AgenticLoop.OMNI,\n",
" ai_provider=LLMProvider.ANTHROPIC,\n",
" model='claude-3-7-sonnet-20250219',\n",
" save_trajectory=True,\n",
" trajectory_dir=str(Path(\"trajectories\") / datetime.now().strftime(\"%Y%m%d_%H%M%S\")),\n",
" only_n_most_recent_images=3, # Slightly different from the omni example\n",
" verbosity=logging.INFO,\n",
")\n",
"\n",
"tasks = [\n",
"\"\"\"\n",
"Please help me with the following task:\n",
"1. Open Safari browser\n",
"2. Go to Wikipedia.org\n",
"3. Search for \"Claude AI\" \n",
"4. Summarize the main points you find about Claude AI\n",
"\"\"\"\n",
"]\n",
"\n",
"async with agent:\n",
" for i, task in enumerate(tasks, 1):\n",
" print(f\"\\nExecuting task {i}/{len(tasks)}: {task}\")\n",
" async for result in agent.run(task):\n",
" print(result)\n",
" print(f\"Task {i} completed\")\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

506
notebooks/computer_nb.ipynb Normal file
View File

@@ -0,0 +1,506 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Computer\n",
"\n",
"This notebook demonstrates how to use Computer to operate a Lume sandbox programmatically on Apple Silicon macOS systems."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Installation"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip uninstall -y cua-computer"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install cua-computer"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# If locally installed, use this instead:\n",
"import os\n",
"\n",
"os.chdir('../libs/computer')\n",
"!poetry install\n",
"!poetry build\n",
"\n",
"!pip uninstall cua-computer -y\n",
"!pip install ./dist/cua_computer-0.1.0-py3-none-any.whl --force-reinstall"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Lume daemon\n",
"\n",
"While a `lume` binary is included with Computer, we recommend installing the standalone version with brew, and starting the lume daemon service before running Computer. Refer to [../libs/lume/README.md](../libs/lume/README.md) for more details on lume cli."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!brew tap trycua/lume\n",
"!brew install lume"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Start the lume daemon service (from another terminal):\n",
"\n",
"```bash\n",
"lume serve\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Pull the latest pre-built macos-sequoia-cua image. This image, based on macOS Sequoia, contains all dependencies needed to be controlled from the Computer interface."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!lume pull macos-sequoia-cua:latest"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The initial image download of thew macos-sequoia-cua image requires 80GB of storage space. However, after the first run, the image size reduces to around 20GB. Thanks to macOS's sparse file system, VM disk space is allocated dynamically - while VMs may show a total size of 50GB, they typically only consume about 20GB of physical disk space.\n",
"\n",
"Sandbox are stored in `~/.lume`, and locally cached images are stored in `~/.lume/cache`.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can always see the list of downloaded VM images with:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!lume ls"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Testing the sandbox\n",
"\n",
"Once downloaded, you can run the sandbox to test everything is working:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!lume run macos-sequoia-cua:latest"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can add additional software and tools to the sandbox - these changes will be saved in the VM disk."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Initialize a Computer instance"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Computer allows you to create and control a virtual sandbox instances from your host on Apple Silicon. Here's a basic example:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from computer import Computer"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can either use the async context manager or initialize the Computer instance directly."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"With the async context manager:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"async with Computer(\n",
" # name=\"my_vm\", # optional, in case you want to use any other VM created using lume\n",
" display=\"1024x768\",\n",
" memory=\"8GB\",\n",
" cpu=\"4\",\n",
" os=\"macos\"\n",
") as computer:\n",
" await computer.run()\n",
" # ... do something with the computer interface"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Direct initialization:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"computer = Computer(\n",
" display=\"1024x768\",\n",
" memory=\"8GB\",\n",
" cpu=\"4\",\n",
" os=\"macos\"\n",
")\n",
"\n",
"await computer.run()\n",
"# ... do something with the computer interface"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The Computer instance requires a Lume server for communication. Here's how it works:\n",
"\n",
"1. First, it attempts to connect to any existing Lume server running on port 3000\n",
"2. If no Lume server is available, it automatically starts a new one via [lume serve](https://github.com/trycua/lume/?tab=readme-ov-file#local-api-server)\n",
"\n",
"The sandbox's lifecycle is tied to the Lume server:\n",
"- If Computer started the Lume server itself, the server will be terminated when Computer stops\n",
"- If Computer connected to a pre-existing server, that server remains running after Computer stops\n",
"\n",
"If you have scenarios where you need to run multiple sandboxes in parallel, we recommend first starting the Lume server separately with `lume serve` (refer to [Lume](https://github.com/trycua/lume/?tab=readme-ov-file#install) on how to install) and then having each Computer instance connect to it."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In order to execute commands targeting the sandbox, the Computer interface communicates through websockets to a Fast API server running on the sandbox."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Cursor"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"# Move and click\n",
"await computer.interface.move_cursor(100, 100)\n",
"await computer.interface.left_click()\n",
"await computer.interface.right_click(300, 300)\n",
"await computer.interface.double_click(400, 400)\n",
"\n",
"# Drag operations\n",
"await computer.interface.drag_to(500, 500, duration=1.0)\n",
"\n",
"# Get cursor position\n",
"cursor_pos = await computer.interface.get_cursor_position()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Keyboard"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"# Type text\n",
"await computer.interface.type_text(\"Hello, World!\")\n",
"\n",
"# Press individual keys\n",
"await computer.interface.press_key(\"enter\")\n",
"await computer.interface.press_key(\"escape\")\n",
"\n",
"# Use hotkeys\n",
"await computer.interface.hotkey(\"command\", \"c\") # Command+C on macOS"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Screen"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"# Get screen dimensions\n",
"screen_size = await computer.interface.get_screen_size()\n",
"\n",
"# Take basic screenshot\n",
"screenshot = await computer.interface.screenshot()\n",
"with open(\"screenshot.png\", \"wb\") as f:\n",
" f.write(screenshot)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Clipboard"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Set clipboard content\n",
"await computer.interface.set_clipboard(\"Text to copy\")\n",
"\n",
"# Get clipboard content\n",
"clipboard_content = await computer.interface.copy_to_clipboard()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### File System Operations"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Check file/directory existence\n",
"file_exists = await computer.interface.file_exists(\"/path/to/file.txt\")\n",
"dir_exists = await computer.interface.directory_exists(\"/path/to/directory\")\n",
"\n",
"# Run shell commands\n",
"stdout, stderr = await computer.interface.run_command(\"ls -la\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Accessibility"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"# Get accessibility tree\n",
"accessibility_tree = await computer.interface.get_accessibility_tree()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Sharing a directory with the sandbox"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can share a directory with the sandbox by passing a list of absolute paths to the `shared_directories` argument when initializing the Computer instance."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"computer = Computer(\n",
" display=\"1024x768\",\n",
" memory=\"4GB\",\n",
" cpu=\"2\",\n",
" os=\"macos\",\n",
" shared_directories=[\"/absolute/path/to/directory\"]\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Using Host Computer\n",
"\n",
"For local development and testing purposes, you can run the Computer API server on the same host machine and target it instead:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"computer = Computer(\n",
" display=\"1024x768\",\n",
" memory=\"4GB\",\n",
" cpu=\"2\",\n",
" os=\"macos\",\n",
" use_host_computer_server=True\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Examples"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"from computer.computer import Computer"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"async with Computer(\n",
" display=\"1024x768\",\n",
" memory=\"4GB\",\n",
" cpu=\"2\",\n",
" os=\"macos\"\n",
") as computer:\n",
" await computer.run()\n",
" res = await computer.interface.run_command(\"ls -a\")\n",
"\n",
" # Get screen dimensions\n",
" screen_size = await computer.interface.get_screen_size()\n",
"\n",
" # Move and click\n",
" await computer.interface.move_cursor(100, 100)\n",
" await computer.interface.left_click()\n",
" await computer.interface.right_click(300, 300)\n",
" await computer.interface.double_click(400, 400)\n",
"\n",
" # Drag operations\n",
" await computer.interface.drag_to(500, 500, duration=1.0)\n",
"\n",
" # Get cursor position\n",
" cursor_pos = await computer.interface.get_cursor_position()\n",
"\n",
" # Your automation code here\n",
" await computer.stop()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@@ -0,0 +1,117 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Computer Server\n",
"\n",
"This notebook demonstrates how to host the server used by Computer."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Installation"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install cua-computer-server"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# If locally installed, use this instead:\n",
"import os\n",
"\n",
"os.chdir('../libs/computer-server')\n",
"!pdm install\n",
"!pdm build\n",
"\n",
"!pip uninstall cua-computer-server -y\n",
"!pip install ./dist/cua_computer_server-0.1.0-py3-none-any.whl --force-reinstall"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Start the Computer server"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"==> Starting computer-server on 0.0.0.0:8000...\n",
"Starting computer-server on 0.0.0.0:8000...\n",
"\u001b[32mINFO\u001b[0m: Started server process [\u001b[36m65480\u001b[0m]\n",
"\u001b[32mINFO\u001b[0m: Waiting for application startup.\n",
"\u001b[32mINFO\u001b[0m: Application startup complete.\n",
"\u001b[32mINFO\u001b[0m: Uvicorn running on \u001b[1mhttp://0.0.0.0:8000\u001b[0m (Press CTRL+C to quit)\n",
"^C\n",
"\u001b[32mINFO\u001b[0m: Shutting down\n",
"\u001b[32mINFO\u001b[0m: Waiting for application shutdown.\n",
"\u001b[32mINFO\u001b[0m: Application shutdown complete.\n",
"\u001b[32mINFO\u001b[0m: Finished server process [\u001b[36m65480\u001b[0m]\n"
]
}
],
"source": [
"import os\n",
"# os.chdir('../../scripts')\n",
"\n",
"! ./run_computer_server.sh\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Synchronous usage\n",
"from computer_server import Server\n",
"\n",
"server = Server(port=8000)\n",
"server.start() # Blocks until stopped"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

348
notebooks/pylume_nb.ipynb Normal file
View File

@@ -0,0 +1,348 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Intro\n",
"\n",
"This notebook provides a quickstart guide to the pylume python library."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip uninstall pylume -y"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install pylume"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# If locally installed, use this instead:\n",
"# !poetry install\n",
"# !poetry build\n",
"!pip uninstall pylume -y && pip install ./dist/pylume-0.1.0-py3-none-any.whl --force-reinstall"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"import asyncio\n",
"from pylume import (\n",
" PyLume, \n",
" ImageRef, \n",
" VMRunOpts, \n",
" SharedDirectory, \n",
" VMConfig,\n",
" VMUpdateOpts\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Get latest IPSW URL from Apple Server\n",
"\n",
"This is used to create a new macOS VM by providing the downloaded IPSW file path to the `ipsw` argument in the `create_vm` method."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"async def get_ipsw():\n",
" async with PyLume(port=3000) as pylume:\n",
" url = await pylume.get_latest_ipsw_url()\n",
" print(f\"Latest IPSW URL: {url}\")\n",
"\n",
"await get_ipsw()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Create a new VM"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### macOS\n",
"\n",
"An IPSW file path is required to create a new macOS VM. To fetch automatically the latest IPSW during the VM creation, use `ipsw=\"latest\"`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"async def create_macos_vm():\n",
" async with PyLume() as pylume:\n",
" vm_config = VMConfig(\n",
" name=\"macos-vm\",\n",
" os=\"macOS\",\n",
" cpu=4,\n",
" memory=\"4GB\",\n",
" disk_size=\"40GB\",\n",
" display=\"1024x768\",\n",
" ipsw=\"latest\"\n",
" )\n",
" await pylume.create_vm(vm_config)\n",
"\n",
"await create_macos_vm()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Linux\n",
"\n",
"To create a new Linux VM, use the `os=\"linux\"` argument in the `VMConfig` class. Note that this doesn't set up any Linux distribution, it just creates a VM with a Linux kernel."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"async def create_linux_vm():\n",
" async with PyLume() as pylume:\n",
" vm_config = VMConfig(\n",
" name=\"linux-vm\",\n",
" os=\"linux\",\n",
" cpu=2,\n",
" memory=\"4GB\",\n",
" disk_size=\"25GB\",\n",
" display=\"1024x768\"\n",
" )\n",
" await pylume.create_vm(vm_config)\n",
"\n",
"await create_linux_vm()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Pull an image from ghcr.io/trycua"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Cua provides pre-built images for macOS and Linux."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"async def pull_macos_image():\n",
" async with PyLume() as pylume:\n",
" image_ref = ImageRef(\n",
" image=\"macos-sequoia-vanilla\",\n",
" tag=\"15.2\",\n",
" registry=\"ghcr.io\",\n",
" organization=\"trycua\"\n",
" )\n",
" await pylume.pull_image(image_ref, name=\"macos-sequoia-vanilla\")\n",
"\n",
"await pull_macos_image()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Run\n",
"\n",
"Run a VM by providing the `VMRunConfig` object."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"async def run_vm():\n",
" async with PyLume() as pylume:\n",
" vm_name = \"macos-sequoia-vanilla\"\n",
" run_opts = VMRunOpts(\n",
" no_display=False,\n",
" shared_directories=[\n",
" SharedDirectory(\n",
" host_path=\"/Users/<USER>/Shared\",\n",
" read_only=False\n",
" )\n",
" ]\n",
" )\n",
" await pylume.run_vm(vm_name, run_opts)\n",
"\n",
"await run_vm()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### List existing VMs\n",
"\n",
"VMs are stored in the `~/.lume` directory."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"async with PyLume() as pylume:\n",
" vms = await pylume.list_vms()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Get VM status"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"async with PyLume() as pylume:\n",
" status = await pylume.get_vm(\"macos-sequoia-vanilla\")\n",
" print(status)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Update VM Settings"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"update_config = VMUpdateOpts(\n",
" cpu=8,\n",
" memory=\"8GB\"\n",
")\n",
"async with PyLume() as pylume:\n",
" await pylume.update_vm(\"macos-sequoia-vanilla\", update_config)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Stop a VM"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"async with PyLume() as pylume:\n",
" await pylume.stop_vm(\"macos-sequoia-vanilla\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Delete a VM"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"async with PyLume() as pylume:\n",
" await pylume.delete_vm(\"linux-vm\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Images\n",
"\n",
"List the images available locally"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"async with PyLume() as pylume:\n",
" await pylume.get_images()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}