Feature
Background Execution
Run long-running processes without blocking. Start jobs, continue with other work, and check back when they're done.
background.py
1from hopx_ai import Sandbox
2
3sandbox = Sandbox.create(template="code-interpreter")
4
5# Start a long-running process in the background
6process = sandbox.run_code_background("""
7import time
8for i in range(100):
9 print(f"Processing batch {i+1}/100")
10 time.sleep(60) # 1 minute per batch
11print("All batches complete!")
12""")
13
14print(f"Started background process: {process.id}")
15print(f"Status: {process.status}")
16
17# Continue with other work...
18# The process runs independently
19
20# Check on it later
21processes = sandbox.list_processes()
22for p in processes:
23 print(f"{p.id}: {p.status}")
24
25# Kill if needed
26# sandbox.kill_process(process.id)Non-Blocking
Start processes and continue with other work without waiting
Long-Running
Run jobs for hours or days without timeouts or forced shutdowns
Async Webhooks
Get notified when background executions complete
Process Control
List, monitor, and terminate background processes anytime