Python SDK (voidrun)
The official Python 3.9+ client for VoidRun: Pydantic models, generated OpenAPI client under voidrun.api_client, and high-level names aligned with the TypeScript SDK. This page is a structured reference; the PyPI readme and repo examples/ contain the full script catalog.
PyPI
Package and versions
Hub
Auth, base URL, REST overview
Requirements and install
- Python 3.9+
- Dependencies include httpx, Pydantic v2, websockets, etc. (see
pyproject.tomlin the repo)
Configuration
You need an API key. The API base URL defaults to the same hosted endpoint as the TypeScript SDK (DEFAULT_API_BASE_URL, aligned with OpenAPI servers). You set VR_API_URL / API_URL or base_url= only when you use a self-hosted API: see Self-hosted deployments.
Exported defaults
Aligned with@voidrun/sdk:
Create sandbox (create_sandbox)
vr.create_sandbox(...) (and await vr.create_sandbox(...) on AsyncVoidRun) call POST /sandboxes. The body matches OpenAPI CreateSandboxRequest. See API Reference → Sandboxes → Create sandbox.
Use snake_case keyword arguments. The client also accepts camelCase aliases where noted (same as the TypeScript SDK field names).
Options
*
name is required on the REST contract; the Python client supplies a generated name when you omit it.
Organization and user identity
EveryPOST /sandboxes call uses X-API-Key (or VR_API_KEY / API_KEY in the client). The platform resolves organization and user from that key:
orgId— the organization the API key belongs to.userId— the user associated with the key (typically the key creator).
org_id and user_id (recommended), the API uses the org and user from the key. If you set VR_ORG_ID on the client, Python may send that as org_id when you do not pass one explicitly; it must still match the key’s organization.
When you pass org_id / user_id (or orgId / userId), the API validates that:
- The API key is authorized for the given organization.
- The given user is an owner or member of that organization.
The VoidRun MCP tool
create_sandbox uses the same CreateSandboxRequest fields as REST and this SDK. See VoidRun MCP.remove() / remove_async() on exit:
Clients: VoidRun and AsyncVoidRun
list_sandboxes returns ListSandboxesResult:
.sandboxes: list ofSandboxinstances.meta:ListSandboxesMeta:total,page,limit,total_pages(snake_case)
labels={"env": "prod", "team": "api"} to match sandboxes containing
every supplied pair (AND semantics). Matching sandboxes may have additional
labels.
AsyncVoidRun supports async with and aclose() for cleanup (including the thread pool used for API calls).
Context managers
- Sync:
with vr.create_sandbox(...) as sandbox:→remove()on exit (see Create sandbox above). - Async:
async with await vr.create_sandbox(...) as sandbox:→remove_async()on exit
Sandbox lifecycle
OnSandbox:
sleep()/sleep_async()— snapshot the VM (status becomessnapshotted)wake()/wake_async()— restore from snapshot back torunningstart()/start_async()— recovery boot forsnapshotted/killed/errorsandboxesupdate(auto_sleep=...)/update_async()—PATCH /sandboxes/{id}; currentlyauto_sleeponlystop()/pause()— aliases ofsleep(); async variants aliassleep_async()resume()— alias ofwake();resume_async()aliaseswake_async()remove()/remove_async()— delete the sandbox on the APIinfo()— returnsself(refreshed view)
delete / delete_async map to remove.
Any API call against a snapshotted sandbox transparently wakes it, so you usually don’t need to call wake() yourself. See Sandbox lifecycle for the full state machine.
Notable attributes include id, name, cpu, mem, status, image, env_vars, region, org_id, and immutable labels.
Public URLs
Publish ports at create time (or update them later), then fetch the public URLs from the sandbox instance:AsyncVoidRun exposes get_public_urls_async and get_public_url_async on the sandbox. See Public URLs for the full behaviour, including cold-wake on the first request.
Shell execution (exec)
You can pass a string, keyword args, or a generated ExecRequest:
VoidRunResponse[ExecResponseData]: the HTTP envelope is unwrapped so .data is already ExecResponseData:
.data.stdout / .data.stderr / .data.exit_code: not .data.data.* (single .data).
Streaming (exec_stream)
Provide on_stdout, on_stderr, on_exit, on_error for SSE-style streaming.
Code interpreter (run_code / interpreter)
sandbox.run_code(code, language=..., ...) and sandbox.interpreter.run(...) return CodeExecutionResult directly (no extra .data wrapper):
python, javascript, typescript, node, bash, sh: confirm on your deployment.
Background commands
File system (sandbox.fs)
Snake_case methods mirror the TS surface, for example:
- Write:
create_file,upload_file,upload_file_from_path - Read:
download_file - Manage:
delete_file,list_files,stat_file,create_directory,move_file,copy_file,change_permissions - Utilities:
head_tail,search_files,disk_usage - Archives:
compress_file,extract_archive
File watching (async)
sandbox.fs.watch is async: use AsyncVoidRun and await sandbox.fs.watch(...):
PTY (sandbox.pty)
await connect(...)(async): ephemeral or persistent (session_id=).create_session()/create_session_async(): persistent session; readsession_idfrom the nested response model (typicallyresp.data.data.session_idon the Pydantic envelope; inspect types if your spec differs).run_command,resize,list,delete_session.
Naming: snake_case and camelCase
Beyondcreate_sandbox, most Python methods use snake_case. A few kwargs accept camelCase aliases for parity with TypeScript (documented per method in the PyPI readme).
Error handling
Failures raiseApiException (and related) from voidrun.api_client.rest with HTTP status and body. Parse error and details from JSON bodies when present.
Runnable examples and tests
From thepy-sdk repo root (with PYTHONPATH set, e.g. to the package root):
pytest tests/ or hatch run test.
OpenAPI regeneration
Regeneratevoidrun.api_client when voidrun/openapi.yml changes. After regen, confirm sandbox status enum values still match the live server: running, snapshotted, error, killed, deleted.
Next steps
Quickstart
End-to-end first sandbox
Code execution
Exec, interpreter, timeouts
TypeScript SDK
Same concepts, camelCase API
API Reference
OpenAPI tab in this docs site

