Official Python SDK and CLI for InstaVM APIs
Project description
InstaVM Python SDK + CLI
Official Python SDK and installed CLI for InstaVM. Use it to manage VMs, snapshots, shares, volumes, desktops, account settings, and code execution from Python or your shell.
Installation
pip install instavm
Requirements: Python 3.8+
CLI
pip install instavm installs the instavm command in the active Python environment.
instavm --help
python -m instavm.cli --help
The CLI stores defaults in ~/.instavm/config.json, checks INSTAVM_API_KEY when no key is stored, and also respects INSTAVM_BASE_URL and INSTAVM_SSH_HOST.
Auth & Config
instavm auth set-key
instavm auth status
printf '%s' "$INSTAVM_API_KEY" | instavm auth set-key
Common Commands
instavm whoami
instavm ls
instavm create --type computer-use --memory 4096
instavm connect vm_123
instavm snapshot ls
instavm volume ls
instavm volume files upload <volume_id> ./README.md --path docs/README.md
instavm share create vm_123 3000 --public
instavm share set-private <share_id>
instavm ssh-key list
instavm desktop viewer <session_id>
instavm doc
instavm billing
Command Reference
auth:set-key,status,logoutwhoami: show account details and SSH keyscreate/new,ls/list,rm/delete,clone,connect: core VM workflowssnapshot:ls,create,build,get,rmdesktop:status,start,stop,viewervolume:ls,get,create,update,rm,checkpoint,filesshare:create,set-public,set-private,revokessh-key:list,add,removedoc/docs,billing: docs and billing links
All leaf commands support --json. Share visibility updates use share_id, which matches the public API.
Library Quick Start
import os
from instavm import InstaVM
client = InstaVM(
api_key=os.environ.get("INSTAVM_API_KEY"),
auto_start_session=False,
)
me = client.get_current_user()
vms = client.vms.list()
print(me["email"])
print(len(vms))
Table of Contents
- CLI
- Library Quick Start
- Code Execution
- Sessions & Sandboxes
- VMs & Snapshots
- Volumes
- Networking
- Browser Automation
- Computer Use
- Platform APIs
- Error Handling
- Development & Testing
- Further Reading
- Changelog
Code Execution
Sessions & Configuration
from instavm import InstaVM
client = InstaVM(
api_key="your_api_key",
cpu_count=2,
memory_mb=1024,
env={"APP_ENV": "dev"},
metadata={"team": "platform"},
)
result = client.execute("print('session id:', 'ok')")
print(result)
print(client.session_id)
File Operations
client = InstaVM(api_key="your_api_key")
client.upload_file("local_script.py", "/app/local_script.py")
client.execute("python /app/local_script.py", language="bash")
client.download_file("output.json", local_path="./output.json")
Async Execution
client = InstaVM(api_key="your_api_key")
task = client.execute_async("sleep 5 && echo 'done'", language="bash")
result = client.get_task_result(task["task_id"], poll_interval=2, timeout=60)
print(result)
Sessions & Sandboxes
client = InstaVM(api_key="your_api_key")
# Get the publicly-reachable app URL (optionally for a specific port)
app_url = client.get_session_app_url(port=8080)
print(app_url.get("app_url"))
# List sandbox records with optional metadata filter and limit
sandboxes = client.list_sandboxes(metadata={"env": "production"}, limit=50)
print(len(sandboxes))
VMs & Snapshots
client = InstaVM(api_key="your_api_key")
# Create a basic VM
vm = client.vms.create(wait=True, metadata={"purpose": "dev"})
# Create a VM with pre-attached volumes
vm_with_vols = client.vms.create(
wait=True,
volumes=[{"volume_id": "vol_abc", "mount_path": "/data", "mode": "rw"}],
)
# List VMs
vms = client.vms.list() # GET /v1/vms (running)
all_records = client.vms.list_all_records() # GET /v1/vms/ (all records)
# Snapshot a running VM
snap_from_vm = client.vms.snapshot(vm_id=vm["vm_id"], wait=True, name="dev-base")
# Build a snapshot from an OCI image
snap_from_oci = client.snapshots.create(
oci_image="docker.io/library/python:3.11-slim",
name="python-3-11-dev",
vcpu_count=2,
memory_mb=1024,
snapshot_type="user",
build_args={
"git_clone_url": "https://github.com/example/repo.git",
"git_clone_branch": "main",
"envs": {"PIP_INDEX_URL": "https://pypi.org/simple"},
},
)
user_snaps = client.snapshots.list(snapshot_type="user")
Volumes
Volume CRUD & Files
client = InstaVM(api_key="your_api_key")
# Create
volume = client.volumes.create(name="project-data", quota_bytes=10 * 1024 * 1024 * 1024)
volume_id = volume["id"]
# Read / Update
client.volumes.list(refresh_usage=True)
client.volumes.get(volume_id, refresh_usage=True)
client.volumes.update(volume_id, name="project-data-v2", quota_bytes=20 * 1024 * 1024 * 1024)
# File operations
client.volumes.upload_file(volume_id, file_path="./README.md", path="docs/README.md", overwrite=True)
files = client.volumes.list_files(volume_id, prefix="docs/", recursive=True, limit=1000)
download = client.volumes.download_file(volume_id, path="docs/README.md")
client.volumes.delete_file(volume_id, path="docs/README.md")
# Checkpoints
checkpoint = client.volumes.create_checkpoint(volume_id, name="pre-release")
client.volumes.list_checkpoints(volume_id)
client.volumes.delete_checkpoint(volume_id, checkpoint["id"])
# Cleanup
client.volumes.delete(volume_id)
VM Volume Attachments
vm = client.vms.create(wait=True)
vm_id = vm["vm_id"]
client.vms.mount_volume(vm_id, volume_id, mount_path="/data", mode="rw", wait=True)
client.vms.list_volumes(vm_id)
client.vms.unmount_volume(vm_id, volume_id, mount_path="/data", wait=True)
Networking
Egress, Shares, SSH
client = InstaVM(api_key="your_api_key")
# Egress policy
policy = client.set_session_egress(
allow_package_managers=True,
allow_http=False,
allow_https=True,
allowed_domains=["pypi.org", "files.pythonhosted.org"],
)
# Public/private share links
share = client.shares.create(port=3000, is_public=False)
client.shares.update(share_id=share["share_id"], is_public=True)
# SSH key registration
key = client.add_ssh_key("ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA... user@host")
Browser Automation
Basic Browser Flow
client = InstaVM(api_key="your_api_key")
session = client.browser.create_session(viewport_width=1366, viewport_height=768)
session.navigate("https://example.com")
links = session.extract_elements("a", ["text", "href"])
shot_b64 = session.screenshot(full_page=True)
session.close()
Content Extraction
LLM-friendly extraction with optional interactive-element and anchor discovery:
client = InstaVM(api_key="your_api_key")
content = client.browser.extract_content(
url="https://example.com/docs",
include_interactive=True,
include_anchors=True,
max_anchors=30,
)
print(content["readable_content"].get("title"))
for anchor in (content.get("content_anchors") or [])[:5]:
print(anchor.get("text"), anchor.get("selector"))
Computer Use
Control a full desktop environment inside a VM session:
client = InstaVM(api_key="your_api_key")
session_id = client.session_id
# Viewer URL and state
viewer = client.computer_use.viewer_url(session_id)
state = client.computer_use.get(session_id, "/state")
# Proxy methods (GET, POST, HEAD)
head_resp = client.computer_use.head(session_id, "/state")
# VNC websockify URL for remote desktop streaming
vnc = client.computer_use.vnc_websockify(session_id)
Platform APIs
API keys, audit logs, and webhooks:
client = InstaVM(api_key="your_api_key")
# API Keys
api_key = client.api_keys.create(description="ci key")
# Audit log
audit_page = client.audit.events(limit=25, status="success")
# Webhooks
endpoint = client.webhooks.create_endpoint(
url="https://example.com/instavm/webhook",
event_patterns=["vm.*", "snapshot.*"],
)
deliveries = client.webhooks.list_deliveries(limit=10)
Error Handling
All SDK errors extend a typed hierarchy for precise except handling:
from instavm import (
InstaVM,
AuthenticationError,
ExecutionError,
NetworkError,
RateLimitError,
SessionError,
)
client = InstaVM(api_key="your_api_key")
try:
client.execute("raise Exception('boom')")
except AuthenticationError:
print("Invalid API key")
except RateLimitError:
print("Rate limited")
except SessionError as exc:
print(f"Session issue: {exc}")
except ExecutionError as exc:
print(f"Execution failed: {exc}")
except NetworkError as exc:
print(f"Network issue: {exc}")
Development & Testing
pip install -e . # Install for development
python3 -m pytest tests/test_api_client.py -v # Unit tests
Further Reading
- Python SDK Overview
- VM Management
- Snapshots
- Egress and Networking
- Platform APIs
- Browser Automation
- Error Handling
Changelog
Current package version: 0.15.0
0.15.0
- Installed
instavmCLI forpip install instavm, includingpython -m instavm.cli - Stored CLI auth/config in
~/.instavm/config.jsonwithINSTAVM_API_KEYfallback - Added
get_current_user()andget_session_status(session_id=None)helpers for account and desktop workflows
0.13.0
get_session_app_url(session_id?, port?)— session app URL with optional portlist_sandboxes(metadata?, limit?)— list sandbox records with metadata filteringcomputer_use.head(session_id, path)— HEAD proxy method for computer-use sessionscomputer_use.vnc_websockify(session_id)— VNC websockify URL for remote desktop streaming- VM creation now accepts
volumesfor pre-attached volume mounts
0.12.0
- Manager-based APIs across VMs, volumes, snapshots, shares, custom domains, computer use, API keys, audit, and webhooks
- Snapshot build args support for env vars and Git clone inputs
- Distinct VM list helpers for
/v1/vmsand/v1/vms/
For detailed history, see repository tags and PR history.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file instavm-0.15.0.tar.gz.
File metadata
- Download URL: instavm-0.15.0.tar.gz
- Upload date:
- Size: 52.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20ad4c58c2cd49e940c4698e8e60a410ae876e243a5cda9ea2c11c61e9e581a6
|
|
| MD5 |
fc97cd3872562f102dc8729a99c8db77
|
|
| BLAKE2b-256 |
bba75f6bff40319302c9a25afdc37c8651dc06fda5a9b0c496c12be6f2171382
|
File details
Details for the file instavm-0.15.0-py3-none-any.whl.
File metadata
- Download URL: instavm-0.15.0-py3-none-any.whl
- Upload date:
- Size: 54.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09147b391c92d2c205cbf8ae4dda90fef95d4f8e8c483a1a29ca39b24b114c2a
|
|
| MD5 |
7d1679b3cfdf5d6581eea967e93a2f5d
|
|
| BLAKE2b-256 |
061d36c5ed7e14f960743f733f642ca498dc397ab53310cf4b2fea29b50084c8
|