Skip to main content
Optimize your Hopx usage to reduce costs while maintaining performance. This page summarizes key cost optimization strategies.
For detailed cost optimization guidance, see the Cost Optimization page in Core Concepts.

Quick Tips

1. Use Smaller Resources

Start with minimal resources and scale up if needed:
  • Python
  • JavaScript/TypeScript
from hopx_ai import Sandbox

# ✅ Good: Start with minimal resources
sandbox = Sandbox.create(
    template="code-interpreter",
    vcpu=1,
    memory_mb=512,
    disk_gb=5
)

2. Delete When Done

Always delete sandboxes after use:
  • Python
  • JavaScript/TypeScript
from hopx_ai import Sandbox

# ✅ Good: Automatic cleanup with timeout
sandbox = Sandbox.create(template="code-interpreter", timeout_seconds=600)
result = sandbox.run_code("print('Hello')")
# Sandbox automatically killed after 600 seconds

3. Use Pause Instead of Keeping Running

Pause preserves state but costs less than keeping sandboxes running:
  • Python
  • JavaScript/TypeScript
from hopx_ai import Sandbox

sandbox = Sandbox.create(template="code-interpreter")
sandbox.run_code("setup_code()")

# Pause when not in use (cheaper than keeping running)
sandbox.pause()

# Resume later
sandbox.resume()
sandbox.run_code("continue_work()")

4. Reuse Sandboxes

Reuse sandboxes for multiple operations:
  • Python
  • JavaScript/TypeScript
from hopx_ai import Sandbox

# ✅ Good: Reuse sandbox for multiple operations
with Sandbox.create(template="code-interpreter") as sandbox:
    sandbox.run_code("task1()")
    sandbox.run_code("task2()")
    sandbox.run_code("task3()")
# Better than creating 3 separate sandboxes

Cost Comparison

StrategyCost ImpactUse Case
Minimal resourcesLowSimple scripts, testing
Right-sized resourcesMediumProduction workloads
Over-provisionedHigh❌ Avoid unless necessary
Reuse sandboxesLowMultiple operations
Create per operationHigh❌ Avoid
Pause when idleLowIntermittent workloads
Keep runningHigh❌ Avoid for idle sandboxes

Learn More

For comprehensive cost optimization guidance, see: