
Pig is an API to launch and automate Windows apps. Plug this SDK into your AI Agent apps to give them a computer!
Warning: This API and associated infrastructure are currently in alpha and will likely undergo changes.
- Pig Documentation
Install the package using pip:
pip install pig-python
This installation includes both the Python SDK and the pig
command-line interface.
Set up your API key before using the SDK:
export PIG_SECRET_KEY=your_api_key
Apply Here to get your API key.
Here's a simple example to launch and interact with a VM:
from pig import VM
# Create and connect to a new VM
vm = VM()
print("Starting VM...")
conn = vm.connect() # Initial boot takes a few minutes
# Interact with the VM
conn.mouse_move(100, 100)
conn.left_click(100, 100)
conn.type("Hello, World!")
To reconnect to an existing VM:
vm = VM(id="VM-ABCDEFG-ABCDEFG-ABCDEFG")
conn = vm.connect()
conn.type("Hello Again!")
Hint: if you don't know the VM ID, you can use the
pig ls
CLI command to list all VMs.
Always clean up your VMs when finished:
# Option 1: Stop VM (persists to disk)
vm.stop()
# Option 2: Terminate VM (deletes the disk)
vm.terminate()
For automated scripts, use the context manager pattern:
with VM().session() as conn:
conn.mouse_move(100, 100)
conn.left_click(100, 100)
# VM automatically stops when the block exits
The context manager ensures your VMs stop.
Warning: During the alpha period, VMs left running without activity may be manually stopped by the Pig team. But please be a good citizen and clean up after yourself.
The pig
CLI provides convenient VM management commands:
# List all VMs
pig ls
# Output format:
ID Status Created
-------------------------- -------- ----------------
VM-6F25BH9-VHENR80-05CRX4Z Running 2025-01-16 06:47
VM-6F228MS-Q0EEQR0-02JT39X Running 2025-01-15 23:45
Available Commands:
pig ls
: List all VMspig create
: Create a new VMpig start <vm_id>
: Start a specific VMpig stop <vm_id>
: Stop a specific VMpig terminate <vm_id>
: Terminate and delete a VM
The VM class is your interface for managing VMs, the cloud machines that run the Windows OS.
VM(
id: Optional[str] = None, # Optionally attach to existing VM.
# If none, new VM will be created.
image: Optional[Windows] = None, # OS image configuration
temporary: bool = False, # If True, terminates VM after session
api_key: Optional[str] = None # API key (alternative to env var)
)
create() -> str
: Creates a new VM and returns its IDconnect() -> Connection
: Connects to the VM, creating if necessarysession() -> VMSession
: Creates a managed VM sessionstart()
: Starts the VMstop()
: Stops the VMterminate()
: Terminates and deletes the VM
Tip: During development and exploration, prefer using the imperative API (
vm.start(), vm.stop()
) so you can watch the VM and experiment. Use the context manager (vm.session()
) once you're ready to automate tasks.
The connection class is your interface for interracting with a running VM. This is what you'll expose as Tools to your agent.
A Connection has the following methods:
cursor_position() -> Tuple[int, int]
: Get current cursor positionmouse_move(x: int, y: int)
: Move cursor to coordinatesleft_click(x: Optional[int], y: Optional[int])
: Left click at current location, or at specified coordinatesleft_click_drag(x: int, y: int)
: Click and drag from current location to target coordinatesdouble_click(x: Optional[int], y: Optional[int])
: Double click at current location, or at specified coordinatesright_click(x: Optional[int], y: Optional[int])
: Right click at current location, or at specified coordinates
type(text: str)
: Type text into VM. Maps to keystrokes, executed with a short delay between each character.key(combo: str)
: Send key combination (e.g., 'ctrl+c', 'alt+Tab'). Supports multiple key strokes separated by space (e.g., 'shift-h i ctrl+a ctrl+c')
screenshot() -> bytes
: Capture screenshot (BMP format)width -> int
: Get VM width (1024)height -> int
: Get VM height (768)
yield_control()
: Transfer control to human operator. This makes all future interactions error until a button is clicked in the UI to grant control back to the agent.await_control()
: Wait for control to be returned to the agent.
Configures Windows VM images.
Windows(version: str = "2025")
.install(application: str) -> Windows # Chain multiple installations
img = (
Windows(version="2025")
.install("Office") # Office is currently the only supported application.
)
vm = VM(image=img)
vm.create()
vm = VM(temporary=True)
with vm.session() as conn:
# VM terminates after block exit, rather than stopping.
# This deletes the VM disk, making it no longer usable.
Environment Variables:
PIG_SECRET_KEY
: API authentication key