Skip to main content

Python SDK for the VirtualFS API — persistent bash sandboxes for AI agents

Project description

virtualfs (Python SDK)

Official Python client for the VirtualFS API — persistent bash sandboxes for AI agents.

Handles JWT minting, JSON serialization, retries, and streaming so callers don't rebuild exec_sync boilerplate every session (see issue #29).

Install

pip install virtualfs-sdk

Local (from this repo):

pip install -e clients/python

Quick start

from virtualfs import Client

with Client(base_url="https://api.example.com", auth_secret="<AUTH_SECRET>", sub="agent-001") as fs:
    sb = fs.sandboxes.create(name="demo", python=True)

    # Execute a script
    result = sb.exec("echo hello && ls /home/user")
    print(result.stdout)        # "hello\n..."
    print(result.error)         # alias for stderr
    print(result.exit_code)     # 0
    print(result.ok)            # True
    print(result.duration_ms)

    # File operations
    sb.fs.write("/home/user/main.py", "print('hi')\n")
    text = sb.fs.read_text("/home/user/main.py")
    entries = sb.fs.tree(prefix="/home/user", depth=2)

    sb.delete()

If you already hold a JWT (e.g. minted via pnpm token:create), pass token= instead of auth_secret=:

fs = Client(base_url="...", token="eyJhbGciOi...")

API surface

Client

Method HTTP Notes
client.sandboxes.list() GET /v1/sandboxes list[SandboxRecord]
client.sandboxes.create(name=, env=, files=, python=, javascript=) POST /v1/sandboxes Sandbox
client.sandboxes.get(id) GET /v1/sandboxes/{id} SandboxInfo
client.sandboxes.attach(id) (no network) Sandbox for an existing id
client.sandboxes.delete(id) DELETE /v1/sandboxes/{id}

Sandbox

Files (sb.fs.*)

Method HTTP
sb.fs.read(path) -> ReadResult GET /files/{path}
sb.fs.read_text(path) -> str GET /files/{path}
sb.fs.write(path, content) PUT /files/{path}
sb.fs.write_files({path: content, ...}) POST /writeFiles
sb.fs.delete(path, recursive=False) DELETE /files/{path}
sb.fs.mkdir(path, recursive=False) POST /mkdir
sb.fs.tree(prefix=, depth=) -> list[TreeEntry] GET /tree

Exec

Method HTTP
sb.exec(script, cwd=, env=, timeout_ms=, debug=) -> ExecResult POST /exec-sync
sb.exec_batch([{id, script}, ...], timeout_ms=) -> list[BatchExecResult] POST /exec-sync-batch
for ev in sb.exec_stream(script, ...) POST /exec (SSE)

Ingest / Export

Method HTTP
sb.ingest_archive(file_obj, base_path=) POST /ingest (multipart)
sb.ingest_files({path: bytes, ...}, base_path=) POST /ingest-files (auto base64)
sb.export(base_path=) -> bytes GET /export
for chunk in sb.export_stream(base_path=) GET /export (streaming)
sb.delete() DELETE /sandboxes/{id}

Errors

All exceptions derive from VirtualFSError. HTTP status codes map to:

Status Exception
400 ValidationError
401 / 403 AuthError
404 NotFoundError
408 ExecTimeoutError (carries .duration_ms)
409 ConflictError
429 RateLimitError (carries .retry_after)
5xx ServerError (after retries exhausted)
network TransportError

Each error exposes .code (server error code, e.g. ENOENT), .status, and .details.

Streaming exec

for event in sb.exec_stream("for i in 1 2 3; do echo $i; sleep 1; done"):
    if event.type == "stdout":
        print(event.data, end="")
    elif event.type == "exit":
        print(f"\nexit={event.exit_code} in {event.duration_ms}ms")

Retries

The SDK retries up to 3 times on 429 and 5xx responses, honouring Retry-After when present and falling back to exponential jitter otherwise. 4xx errors (other than 429) are surfaced immediately. Streaming endpoints are not retried — at-most-once semantics.

Status

Alpha. The SDK lives in this repo so that server-side contract changes can be made together with the SDK in a single PR. It may be split out to a standalone repo once the surface stabilizes.

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

virtualfs_sdk-0.1.0.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

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

virtualfs_sdk-0.1.0-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file virtualfs_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: virtualfs_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for virtualfs_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a09b52f14e1183db9bf78be01afa4fe034c1367a5f3814059497e5b44d430e96
MD5 461670400d28fc940f3ab8f7cca8b108
BLAKE2b-256 40abacb99e8b9b36de1add80f019ae1da12d04419815e83a463312a3ab97189c

See more details on using hashes here.

Provenance

The following attestation bundles were made for virtualfs_sdk-0.1.0.tar.gz:

Publisher: python-sdk-release.yml on Hazzng/virtualFS

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file virtualfs_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: virtualfs_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for virtualfs_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f75a2aabfa8c796aeaad25bcc263262fe6668e9c9e48ce5213bf69bc1c690e1f
MD5 81e910a6f3d6c56fb32db543a7e664e9
BLAKE2b-256 361cae52c9538b747ed0b21f9d0035ab14ac00ebd33e90fba8d5ecc419430fb9

See more details on using hashes here.

Provenance

The following attestation bundles were made for virtualfs_sdk-0.1.0-py3-none-any.whl:

Publisher: python-sdk-release.yml on Hazzng/virtualFS

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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