Last Verified: 2025-01-27
Package:
hopx-ai on PyPI
What is the Python SDK?
The HopX Python SDK provides a simple, powerful interface for creating and managing cloud sandboxes directly from your Python applications. Build AI agents, run untrusted code securely, execute tests in isolation, or process data with rich output capture—all with a clean, Pythonic API. The SDK is a thin wrapper around the HopX REST API that handles authentication, request formatting, error translation, and response parsing automatically, giving you a better developer experience than working with the raw API.Target Audience
This SDK is designed for:- Backend Python developers using Python 3.8+ (CPython recommended)
- Data scientists working with Jupyter notebooks, pandas, matplotlib
- AI/ML engineers building agents that need secure code execution
- DevOps engineers creating isolated testing environments
- Automation engineers building workflows that require sandboxed execution
Supported Runtimes
- Python: 3.8, 3.9, 3.10, 3.11, 3.12 (CPython)
- Operating Systems: Linux, macOS, Windows
- Package Managers: pip, poetry, pipenv, conda
When to Use the SDK vs CLI vs Raw API
Use the Python SDK when:
- ✅ You’re building Python applications
- ✅ You want type hints and IDE autocomplete
- ✅ You prefer Pythonic error handling and exceptions
- ✅ You need async/await support (
AsyncSandbox) - ✅ You want automatic resource management (context managers)
- ✅ You’re working with Python data structures (dicts, lists, models)
Use the CLI when:
- ✅ You prefer command-line workflows
- ✅ You’re scripting or automating from shell
- ✅ You want quick one-off operations
- ✅ You’re working in CI/CD pipelines
- ✅ You need interactive terminal sessions
Use the Raw API when:
- ⚠️ You’re building in a non-Python language
- ⚠️ You need fine-grained control over HTTP requests
- ⚠️ You’re integrating with existing HTTP client libraries
- ⚠️ You need custom retry logic or connection pooling
The SDK is a thin wrapper around the HopX REST API. It handles authentication, request formatting, error translation, and response parsing automatically. For most Python use cases, the SDK provides a better developer experience.
Architecture
The SDK consists of two main classes:Sandbox- Synchronous sandbox client (blocking operations)AsyncSandbox- Asynchronous sandbox client (async/await)
AsyncSandbox optimized for concurrent operations and async frameworks.
Core Capabilities
The Python SDK provides:- Sandbox Management - Create, connect, list, and delete sandboxes
- Code Execution - Run Python, JavaScript, Bash, Go, and more
- Rich Outputs - Capture matplotlib plots, pandas DataFrames, images
- File Operations - Read, write, list, upload, download files
- Command Execution - Run shell commands synchronously or in background
- Environment Variables - Set, get, update, and clear environment variables
- Process Management - List and manage running processes
- Cache Management - Monitor and clear execution result cache
- Desktop Automation - VNC access, mouse/keyboard control (Premium)
- Template Building - Create custom sandbox environments
- WebSocket Streaming - Real-time terminal and code execution streaming
Quick Example
Next Steps
- Installation Guide - Install the SDK and set up your environment
- Quickstart - Get your first sandbox running in minutes
- API Reference - Complete class and method documentation
Related
- JavaScript SDK - Official JavaScript/TypeScript SDK
- CLI Reference - Command-line interface for HopX
- API Reference - Raw REST API documentation
- Core Concepts - Learn about sandboxes, execution, and more

