Skip to main content

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.toml in the repo)
Editable install for development:

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

Every POST /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).
When you omit 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:
  1. The API key is authorized for the given organization.
  2. The given user is an owner or member of that organization.
Mismatched key, user, and org return an error (for example 403 Forbidden).
The VoidRun MCP tool create_sandbox uses the same CreateSandboxRequest fields as REST and this SDK. See VoidRun MCP.
Context managers call remove() / remove_async() on exit:

Clients: VoidRun and AsyncVoidRun

list_sandboxes returns ListSandboxesResult:
  • .sandboxes: list of Sandbox instances
  • .meta: ListSandboxesMeta: total, page, limit, total_pages (snake_case)
Pass 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

On Sandbox:
  • sleep() / sleep_async() — snapshot the VM (status becomes snapshotted)
  • wake() / wake_async() — restore from snapshot back to running
  • start() / start_async() — recovery boot for snapshotted / killed / error sandboxes
  • update(auto_sleep=...) / update_async() — PATCH /sandboxes/{id}; currently auto_sleep only
  • stop() / pause() — aliases of sleep(); async variants alias sleep_async()
  • resume() — alias of wake(); resume_async() aliases wake_async()
  • remove() / remove_async() — delete the sandbox on the API
  • info() — returns self (refreshed view)
Deprecated aliases 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:
Return type: VoidRunResponse[ExecResponseData]: the HTTP envelope is unwrapped so .data is already ExecResponseData:
Use .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):
Languages (typical): python, javascript, typescript, node, bash, sh: confirm on your deployment.

Background commands

See 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(...):
See File watching.

PTY (sandbox.pty)

  • await connect(...) (async): ephemeral or persistent (session_id=).
  • create_session() / create_session_async(): persistent session; read session_id from the nested response model (typically resp.data.data.session_id on the Pydantic envelope; inspect types if your spec differs).
  • run_command, resize, list, delete_session.
Full patterns: PTY and the package README.

Naming: snake_case and camelCase

Beyond create_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 raise ApiException (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 the py-sdk repo root (with PYTHONPATH set, e.g. to the package root):
Tests: pytest tests/ or hatch run test.

OpenAPI regeneration

Regenerate voidrun.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