v0.7.2

Lifetime

Configure how long sandboxes remain active before automatic cleanup.

Configuration

Lifetime is configured during sandbox creation using the lifetime parameter.

lifetimestroptional

Sandbox 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

PropertyValue
FormatDuration string (e.g., 1h, 30m, 1h30m)
Supported unitsh (hours), m (minutes), s (seconds)
Minimum1 minute (1m)
Maximum48 hours (48h)
Default24 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 hour

Long-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 pass

Composite 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()