Understand how sandbox resources (CPU, memory, disk) are configured from templates and how to choose the right template for your workload
Sandbox resources (vCPU, memory, and disk) are automatically configured from templates. You cannot specify custom resources when creating a sandbox - resources are always loaded from the template you choose.
When you create a sandbox from a template, the sandbox automatically gets the resources defined in that template:
Python
JavaScript/TypeScript
Copy
from hopx_ai import Sandbox# Get template details to see its resourcestemplate = Sandbox.get_template("code-interpreter")if template.default_resources: print(f"vCPU: {template.default_resources.vcpu}") print(f"Memory: {template.default_resources.memory_mb} MB") print(f"Disk: {template.default_resources.disk_gb} GB")# Create sandbox - resources come from template automaticallysandbox = Sandbox.create(template="code-interpreter")# Resources are set from template, no need to specify them
Resources are always loaded from templates. To get different resources, choose a different template or create a custom template with your desired resource configuration.
from hopx_ai import Sandbox# List all templatestemplates = Sandbox.list_templates()for t in templates: print(f"{t.name}: {t.display_name}") if t.default_resources: print(f" Resources: {t.default_resources.vcpu} vCPU, " f"{t.default_resources.memory_mb}MB RAM, " f"{t.default_resources.disk_gb}GB disk") print()
from hopx_ai import Sandbox# Filter by categorydev_templates = Sandbox.list_templates(category="development")# Filter by languagepython_templates = Sandbox.list_templates(language="python")# Find templates with specific resourcesfor t in Sandbox.list_templates(): if t.default_resources: if t.default_resources.vcpu >= 4 and t.default_resources.memory_mb >= 4096: print(f"{t.name}: Good for data analysis")
For simple scripts and basic operations, choose templates with minimal resources:
Python
JavaScript/TypeScript
Copy
from hopx_ai import Sandbox# Find lightweight templatestemplates = Sandbox.list_templates()for t in templates: if t.default_resources: if t.default_resources.vcpu <= 2 and t.default_resources.memory_mb <= 1024: print(f"{t.name}: Good for lightweight workloads") sandbox = Sandbox.create(template=t.name) # Use sandbox... sandbox.kill() break
For data analysis with Pandas and visualization, choose templates with 4+ vCPU and 4GB+ RAM:
Python
JavaScript/TypeScript
Copy
from hopx_ai import Sandbox# Use code-interpreter template (typically has good resources for data analysis)template = Sandbox.get_template("code-interpreter")print(f"Resources: {template.default_resources.vcpu} vCPU, " f"{template.default_resources.memory_mb}MB RAM")sandbox = Sandbox.create(template="code-interpreter")# Perfect for data analysisresult = sandbox.run_code("""import pandas as pdimport numpy as npdf = pd.DataFrame({'x': range(1000), 'y': np.random.randn(1000)})print(df.describe())""")sandbox.kill() # Cleanup
For machine learning training and large datasets, choose templates with 16+ vCPU and 16GB+ RAM:
Python
JavaScript/TypeScript
Copy
from hopx_ai import Sandbox# Find high-resource templatestemplates = Sandbox.list_templates()for t in templates: if t.default_resources: if t.default_resources.vcpu >= 16 and t.default_resources.memory_mb >= 16384: print(f"{t.name}: Good for ML training") sandbox = Sandbox.create(template=t.name) # Use for ML training... sandbox.kill() break
You can specify a region when creating a sandbox to minimize latency:
Python
JavaScript/TypeScript
Copy
from hopx_ai import Sandbox# Choose region closest to your userssandbox = Sandbox.create( template="code-interpreter", region="us-west-2" # Oregon, USA)sandbox.kill() # Cleanup
Available regions:
us-west-2 (Oregon, USA)
us-east-1 (Virginia, USA)
eu-west-1 (Ireland, EU)
ap-southeast-1 (Singapore, APAC)
Choose the region closest to your users or data sources to minimize latency. Resources are still determined by the template, not the region.
Start with templates that have minimal resources and scale up if needed:
Python
JavaScript/TypeScript
Copy
from hopx_ai import Sandbox# Start with lightweight templatetemplates = Sandbox.list_templates()lightweight = next(t for t in templates if t.default_resources and t.default_resources.vcpu == 1)sandbox = Sandbox.create(template=lightweight.name)# Test your workload# If you need more, switch to a higher-resource templatesandbox.kill()
Monitor Resource Usage
Use metrics to understand your actual resource needs and choose appropriate templates:
Python
JavaScript/TypeScript
Copy
from hopx_ai import Sandboxsandbox = Sandbox.create(template="code-interpreter")# Run your workloadsandbox.run_code("your_code_here")# Check resource usagemetrics = sandbox.get_metrics()print(f"CPU: {metrics.cpu_percent}%")print(f"Memory: {metrics.memory_used_mb}/{metrics.memory_total_mb} MB")# Use this info to choose the right template next timesandbox.kill()
Choose Templates Wisely
Select templates that match your workload requirements - don’t over-provision:
Python
JavaScript/TypeScript
Copy
from hopx_ai import Sandbox# For simple scripts, use minimal resources# For data analysis, use code-interpreter# For ML training, find high-resource templates# List templates and their resourcestemplates = Sandbox.list_templates()for t in templates: if t.default_resources: print(f"{t.name}: {t.default_resources.vcpu}vCPU, " f"{t.default_resources.memory_mb}MB")