Sandboxes automatically terminate after a timeout period. This prevents runaway costs and ensures resources are released.
Default Timeout
The default timeout is 5 minutes (300 seconds). After this period of inactivity, the sandbox is automatically killed.
from moru import Sandbox
# Default 5-minute timeout
sandbox = Sandbox.create()
# Custom timeout (10 minutes)
sandbox = Sandbox.create(timeout=600)
Maximum Timeout
The maximum timeout for all accounts is 1 hour.
Need longer sandbox duration? Contact us at hi@moru.io.
Extend Timeout
Extend the timeout of a running sandbox:
from moru import Sandbox
sandbox = Sandbox.create()
# Extend timeout by 30 minutes from now
sandbox.set_timeout(1800) # seconds
# Or using static method
Sandbox.set_timeout("sbx_abc123...", 1800)
Check Remaining Time
Get the sandbox info to see when it will terminate:
from moru import Sandbox
from datetime import datetime
sandbox = Sandbox.create()
info = sandbox.get_info()
remaining = info.end_at - datetime.now(info.end_at.tzinfo)
print(f"Sandbox expires in {remaining.total_seconds()} seconds")
Keep-Alive Pattern
For long-running agents, periodically extend the timeout:
import threading
from moru import Sandbox
sandbox = Sandbox.create()
def keep_alive():
while True:
try:
sandbox.set_timeout(600) # Extend by 10 minutes
time.sleep(300) # Check every 5 minutes
except Exception:
break # Sandbox was killed
# Start keep-alive in background
thread = threading.Thread(target=keep_alive, daemon=True)
thread.start()
# Do your work...
Auto-Pause (Beta)
Instead of terminating, sandboxes can automatically pause when idle:
from moru import Sandbox
# Auto-pause after 5 minutes of inactivity
sandbox = Sandbox.beta_create(
template="python",
auto_pause=True,
auto_pause_timeout=300
)
# Do some work
sandbox.commands.run("echo 'Hello'")
# If idle for 5 minutes, sandbox pauses instead of terminating
# Resume later with:
sandbox.connect()
Auto-pause is a beta feature. Paused sandboxes preserve filesystem state but still count toward your quota.
Timeout Errors
When a sandbox times out during an operation:
from moru import Sandbox
from moru.exceptions import TimeoutException
sandbox = Sandbox.create(timeout=60)
try:
# This might timeout if the command takes too long
result = sandbox.commands.run("sleep 120", timeout=90)
except TimeoutException:
print("Command or sandbox timed out")
# Check if sandbox is still running
if not sandbox.is_running():
print("Sandbox was terminated")
Lifecycle Events
The sandbox goes through these states:
- Creating - Sandbox is being provisioned
- Running - Sandbox is active and accepting operations
- Paused (beta) - Sandbox is suspended, can be resumed
- Terminated - Sandbox is stopped, cannot be recovered
Next Steps