Prerequisites
Before you begin, make sure you have:- HopX API key - Get one from console.hopx.dev or see [API key Management](/API key)
- SDK installed - Python SDK (
pip install hopx-ai) or JavaScript SDK (npm install @hopx-ai/sdk) - Basic understanding - Familiarity with the Quickstart Guide is helpful
Overview
When you create a sandbox, HopX:- Spins up a lightweight VM in seconds (~100ms)
- Loads resources (CPU, memory, disk) from the template
- Provides a persistent filesystem during the sandbox lifecycle
- Auto-destroys the sandbox after timeout (if configured)
Resources (vcpu, memory, disk) are always loaded from the template. You cannot specify custom resources when creating a sandbox. To use different resources, create a custom template first.
Basic Creation
The simplest way to create a sandbox is using a template name:- Python
- JavaScript
Using Template ID
You can also create a sandbox using a template ID instead of a name:- Python
- JavaScript
Configuration Options
When creating a sandbox, you can configure several options:Timeout
Set an auto-kill timeout to automatically destroy the sandbox after a specified duration:- Python
- JavaScript
Internet Access
Control whether the sandbox has internet access:- Python
- JavaScript
Environment Variables
Set initial environment variables when creating the sandbox:- Python
- JavaScript
Using Context Managers (Python)
Python SDK supports context managers for automatic cleanup:The context manager automatically calls
sandbox.kill() when exiting the with block, even if an error occurs. This ensures proper cleanup.Finding Available Templates
Before creating a sandbox, you may want to list available templates:- Python
- JavaScript
Best Practices
1
1. Always Clean Up
Use context managers (Python) or try/finally blocks to ensure sandboxes are cleaned up, even if errors occur.
2
2. Set Appropriate Timeouts
Set timeouts based on your use case. For quick scripts, use shorter timeouts. For long-running tasks, set longer timeouts or use timeout management.
3
3. Use Environment Variables
Set environment variables at creation time rather than later for better performance and consistency.
4
4. Choose the Right Template
Select templates that match your needs. Use
list_templates() to find available options.5
5. Handle Errors Gracefully
Always handle potential errors (template not found, resource limits, etc.) in your code.
Implementation
- SDK: Sandbox.create() - Python SDK method
- CLI - Command-line interface
- API: POST /v1/sandboxes - Control Plane API endpoint
Related
- Listing Templates - Find available templates
- Getting Template Details - View template information
- Connecting to Sandboxes - Connect to existing sandboxes
- Managing Sandbox State - Control sandbox lifecycle
Next Steps
- Learn how to List Sandboxes to find existing sandboxes
- Understand Connecting to Existing sandboxes
- Explore Managing State (start, stop, pause, resume)
- Configure Timeout Management for long-running sandboxes

