Lifetime
Configure how long sandboxes remain active before automatic cleanup.
Configuration
Lifetime is configured during sandbox creation using the lifetime parameter.
lifetimestroptionalSandbox lifetime duration string. Defaults to 24 hours. See format below.
Lifetime cannot be modified after creation. Expiration time is available in CONCAVE_EXPIRES_AT.
Format & Limits
| Property | Value |
|---|---|
| Format | Duration string (e.g., 1h, 30m, 1h30m) |
| Supported units | h (hours), m (minutes), s (seconds) |
| Minimum | 1 minute (1m) |
| Maximum | 48 hours (48h) |
| Default | 24 hours (24h) |
Basic Usage
Pass a duration string to the lifetime parameter:
from concave import Sandbox
# Default lifetime (24h)
sbx = Sandbox.create()
# Custom lifetime (5 hours)
sbx = Sandbox.create(lifetime="5h")
# Short-lived sandbox (30 minutes)
sbx = Sandbox.create(lifetime="30m")
# Maximum lifetime (48 hours)
sbx = Sandbox.create(lifetime="48h")Examples
Quick Tasks
from concave import sandbox
with sandbox(lifetime="1h") as sbx:
result = sbx.run("python script.py")
print(result.stdout)
# Automatically cleaned up after 1 hourLong-Running Jobs
from concave import Sandbox
sbx = Sandbox.create(lifetime="48h")
try:
# Start long-running process
result = sbx.execute("nohup ./long_job.sh > output.log 2>&1 &")
print(f"Job started in sandbox {sbx.id}")
print("Sandbox will remain active for 48 hours")
# Save sandbox ID for later retrieval
save_to_database(sbx.id)
finally:
# Don't delete - let it run for 48h
passComposite Duration
from concave import sandbox
# 1 hour and 30 minutes lifetime
with sandbox(lifetime="1h30m") as sbx:
result = sbx.run("pytest tests/")
print(f"Tests completed: {result.returncode == 0}")Check Expiration Time
from concave import Sandbox
sbx = Sandbox.create(lifetime="2h")
# Check when sandbox expires (set inside sandbox)
result = sbx.run("""
import os
from datetime import datetime
expires_at = os.environ.get('CONCAVE_EXPIRES_AT')
created_at = os.environ.get('CONCAVE_CREATED_AT')
print(f"Created: {created_at}")
print(f"Expires: {expires_at}")
""")
print(result.stdout)
sbx.delete()