Skip to main content

Python SDK for VoidRun AI Sandbox

Project description

VoidRun Python SDK

Python SDK for interacting with VoidRun AI Sandboxes. Create sandboxes, execute commands, manage files, watch changes, and use interactive PTY sessions.

PyPI version License: MIT

Features

  • Sandbox lifecycle management
  • Command execution with stdout/stderr capture
  • File system operations (upload, download, list, copy, move)
  • File watching via WebSocket
  • PTY sessions (ephemeral and persistent)
  • Code interpreter helper for common languages
  • Sync and async clients

Installation

With pip:

pip install voidrun

With Poetry:

poetry add voidrun

Quick Start (Sync)

Set your API key:

export VR_API_KEY="your-api-key"

Basic usage:

from voidrun import VoidRun

vr = VoidRun()

resp = vr.sandboxes.create(mem=1024, cpu=1)
sandbox = resp.data

exec_resp = sandbox.exec('echo "Hello from VoidRun"')
print(exec_resp.data.data.stdout)

sandbox.delete()

Quick Start (Async)

import asyncio
from voidrun import AsyncVoidRun


async def main():
    vr = AsyncVoidRun()
    resp = await vr.sandboxes.create(mem=1024, cpu=1)
    sandbox = resp.data

    exec_resp = sandbox.exec('echo "Hello from VoidRun"')
    print(exec_resp.data.data.stdout)

    await sandbox.delete_async()
    await vr.aclose()


asyncio.run(main())

Core Operations

Sandboxes

resp = vr.sandboxes.list()
sandboxes = resp.data

resp = vr.sandboxes.get("sandbox-id")
existing = resp.data

vr.sandboxes.delete("sandbox-id")

Command Execution

result = sandbox.exec("ls -la /home")
print(result.data.data.stdout)
print(result.data.data.stderr)
print(result.data.data.exit_code)

Streaming Execution

def on_stdout(data):
    print("STDOUT:", data)


def on_stderr(data):
    print("STDERR:", data)


sandbox.exec_stream(
    "python3 -c 'print(2 + 2)'",
    on_stdout=on_stdout,
    on_stderr=on_stderr,
)

Code Interpreter

resp = sandbox.run_code("print(2 + 2)", language="python")
print(resp.data.stdout)

File Operations

sandbox.fs.create_file("/tmp/hello.txt")
sandbox.fs.upload_file("/tmp/hello.txt", "Hello, World!")

data = sandbox.fs.download_file("/tmp/hello.txt")
print(data.decode("utf-8"))

files = sandbox.fs.list_files("/tmp")
print(files.data)

File Watching (Async)

async def watch_tmp():
    watcher = await sandbox.fs.watch(
        "/tmp",
        recursive=True,
        on_event=lambda evt: print("event:", evt),
        on_error=lambda err: print("watch error:", err),
    )

    # Stop watching when done
    watcher.close()

PTY Sessions (Async)

session_resp = sandbox.pty.create_session()
session_id = session_resp.data.data.session_id

pty = await sandbox.pty.connect(
    session_id=session_id,
    on_data=lambda data: print(data, end=""),
)

pty.send_input("echo 'hello'\n")
await pty.close()

Configuration

Environment variables:

export VR_API_KEY="your-api-key"
export VOIDRUN_BASE_URL="https://api.voidrun.io"

You can also pass api_key and base_url directly:

vr = VoidRun(api_key="...", base_url="https://api.voidrun.io")

Examples

See the examples in py-sdk/examples.

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

voidrun-0.0.3.tar.gz (55.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

voidrun-0.0.3-py3-none-any.whl (147.2 kB view details)

Uploaded Python 3

File details

Details for the file voidrun-0.0.3.tar.gz.

File metadata

  • Download URL: voidrun-0.0.3.tar.gz
  • Upload date:
  • Size: 55.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for voidrun-0.0.3.tar.gz
Algorithm Hash digest
SHA256 a339f1f31b0a11d3cd1406cf54a6087780735d52e2a3c0092eee63129b4bddc1
MD5 9dca6924336b2440066825d368ce9162
BLAKE2b-256 20980b239ff6c98fd4ac667e6978ac2680c734e2894051294952923c2a40cb42

See more details on using hashes here.

File details

Details for the file voidrun-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: voidrun-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 147.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for voidrun-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f437a24b19a0a536243cc0e2cd4646ea6fc53e74f8638bb4199e3babba4e0687
MD5 22bb9cab2ffd78ecaa486dd6851e4fc3
BLAKE2b-256 8944cf84e50139635aec631e65ef074239dc9d4dc8966ef5d59cdec451166835

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page