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.2.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.2-py3-none-any.whl (147.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: voidrun-0.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 8d16cfcadf0fdf65c5b0aa4a3ed598edb28e927d93b7bb52031acedd537d1af6
MD5 d9a7ba2ec2750fc8b40292d3a94452ee
BLAKE2b-256 78b2493781f65c5e98d3544c09f7c9157f7de3c5baa4260cc9a2c00866735590

See more details on using hashes here.

File details

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

File metadata

  • Download URL: voidrun-0.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 07b7b581509a09c09a5cc094f77fe2dfaad097e68386977c82d4be884336b4af
MD5 a1abf8e58363b133af3e70f26d4f6f40
BLAKE2b-256 4234590d7f5af7f5f29a18c5cf82019659b973d85fe652a810a1712f20f73d05

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