Skip to main content

Hanzo Runtime SDK for Python

A Python SDK for interacting with the Hanzo Runtime API, providing a simple interface for Hanzo Runtime Sandbox management, Git operations, file system operations, and language server protocol support.

Installation

You can install the package using pip:

pip install hanzo-runtime

Quick Start

Here's a simple example of using the SDK:

from hanzo_runtime import HanzoRuntime

# Initialize using environment variables
hanzo_runtime = HanzoRuntime()

# Create a sandbox
sandbox = hanzo_runtime.create()

# Run code in the sandbox
response = sandbox.process.code_run('print("Hello World!")')
print(response.result)

# Clean up when done
hanzo_runtime.delete(sandbox)

Configuration

The SDK can be configured using environment variables or by passing a configuration object:

from hanzo_runtime import HanzoRuntime, HanzoRuntimeConfig

# Initialize with configuration
config = HanzoRuntimeConfig(
    api_key="your-api-key",
    api_url="your-api-url",
    target="us"
)
hanzo_runtime = HanzoRuntime(config)

Or using environment variables:

  • HANZO_RUNTIME_API_KEY: Your Hanzo Runtime API key
  • HANZO_RUNTIME_API_URL: The Hanzo Runtime API URL
  • HANZO_RUNTIME_TARGET: Your target environment

You can also customize sandbox creation:

sandbox = hanzo_runtime.create(CreateSandboxFromSnapshotParams(
    language="python",
    env_vars={"PYTHON_ENV": "development"},
    auto_stop_interval=60,  # Auto-stop after 1 hour of inactivity
    auto_archive_interval=60,  # Auto-archive after a Sandbox has been stopped for 1 hour
    auto_delete_interval=120 # Auto-delete after a Sandbox has been stopped for 2 hours
))

Features

  • Sandbox Management: Create, manage and remove sandboxes
  • Git Operations: Clone repositories, manage branches, and more
  • File System Operations: Upload, download, search and manipulate files
  • Language Server Protocol: Interact with language servers for code intelligence
  • Process Management: Execute code and commands in sandboxes

Examples

Execute Commands

# Execute a shell command
response = sandbox.process.exec('echo "Hello, World!"')
print(response.result)

# Run Python code
response = sandbox.process.code_run('''
x = 10
y = 20
print(f"Sum: {x + y}")
''')
print(response.result)

File Operations

# Upload a file
sandbox.fs.upload_file(b'Hello, World!', 'path/to/file.txt')

# Download a file
content = sandbox.fs.download_file('path/to/file.txt')

# Search for files
matches = sandbox.fs.find_files(root_dir, 'search_pattern')

Git Operations

# Clone a repository
sandbox.git.clone('https://github.com/example/repo', 'path/to/clone')

# List branches
branches = sandbox.git.branches('path/to/repo')

# Add files
sandbox.git.add('path/to/repo', ['file1.txt', 'file2.txt'])

Language Server Protocol

# Create and start a language server
lsp = sandbox.create_lsp_server('typescript', 'path/to/project')
lsp.start()

# Notify the lsp for the file
lsp.did_open('path/to/file.ts')

# Get document symbols
symbols = lsp.document_symbols('path/to/file.ts')

# Get completions
completions = lsp.completions('path/to/file.ts', {"line": 10, "character": 15})

Contributing

Hanzo Runtime is Open Source under the Apache License 2.0, and is the copyright of its contributors. If you would like to contribute to the software, read the Developer Certificate of Origin Version 1.1 (https://developercertificate.org/). Afterwards, navigate to the contributing guide to get started.

Code in _sync directory shouldn't be edited directly. It should be generated from the corresponding async code in the _async directory using the sync_generator.py script.

Metadata

Release files for hanzo-runtime 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hanzo-runtime 0.7.0
File Size Uploaded Provenance
hanzo_runtime-0.7.0.tar.gz 91.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for hanzo-runtime 0.7.0
File Interpreter ABI Platform
hanzo_runtime-0.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 207.1 kB

Release files / hanzo_runtime-0.7.0.tar.gz

Download URL hanzo_runtime-0.7.0.tar.gz
Size 91.7 kB
Tags Source
SHA-256 checksum
How to use checksums
4de4d748fcde6c23b8c5662c459e96a3b84a604e5fee3d983ea3a3adfd573779
BLAKE2b-256 checksum
How to use checksums
dc77181922d6f11616b539019072e18fea0b8596d09c415e387c93726fabd3e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release files / hanzo_runtime-0.7.0-py3-none-any.whl

Download URL hanzo_runtime-0.7.0-py3-none-any.whl
Size 115.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c73177e4296e7f9a0e8f030ef2c5f15bcbaac52f0fb04eb9d494654a4f412f57
BLAKE2b-256 checksum
How to use checksums
7ab83ffe2bfff70062f3a0b6f3b7db903f3998d3e25fd7d9536fd36d6b93072a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Security for hanzo-runtime 0.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page