Overview
Daytona provides automatic lifecycle management to optimize resource usage and costs. Sandboxes can be configured to automatically stop, archive, or delete after periods of inactivity.
Lifecycle Stages
| Stage | Description | Data Preservation |
|---|
| Running | Sandbox is active and consuming resources | Full state |
| Stopped | Sandbox is paused, disk persisted | Full state |
| Archived | Sandbox stored in cold storage | Full state |
| Deleted | Sandbox permanently removed | None |
Auto-Stop
Automatically stop sandboxes after a period of inactivity.
import { Daytona } from '@daytonaio/sdk'
const daytona = new Daytona()
// Auto-stop after 30 minutes of inactivity
const sandbox = await daytona.create({
autoStopInterval: 30 // minutes
})
console.log(`Auto-stop interval: ${sandbox.autoStopInterval} minutes`)
Update Auto-Stop Interval
// Change auto-stop interval on existing sandbox
await sandbox.setAutostopInterval(60) // 1 hour
// Disable auto-stop
await sandbox.setAutostopInterval(0)
await sandbox.refreshData()
console.log(`New auto-stop: ${sandbox.autoStopInterval} minutes`)
Default Auto-Stop
If not specified, sandboxes use a default auto-stop interval of 15 minutes.
Auto-Archive
Automatically archive sandboxes that have been stopped for a specified period.
// Auto-archive after 24 hours of being stopped
const sandbox = await daytona.create({
autoArchiveInterval: 1440 // 24 hours = 1440 minutes
})
console.log(`Auto-archive interval: ${sandbox.autoArchiveInterval} minutes`)
Update Auto-Archive Interval
// Change to 1 hour
await sandbox.setAutoArchiveInterval(60)
// Use maximum interval (organization default)
await sandbox.setAutoArchiveInterval(0)
await sandbox.refreshData()
console.log(`New auto-archive: ${sandbox.autoArchiveInterval} minutes`)
Default Auto-Archive
If not specified, sandboxes use a default auto-archive interval of 7 days (10,080 minutes).
Auto-Delete
Automatically delete sandboxes that have been stopped for a specified period.
Auto-delete permanently removes sandboxes and all their data. This action cannot be undone.
// Auto-delete after 7 days of being stopped
const sandbox = await daytona.create({
autoDeleteInterval: 10080 // 7 days = 10080 minutes
})
console.log(`Auto-delete interval: ${sandbox.autoDeleteInterval} minutes`)
Update Auto-Delete Interval
// Enable auto-delete after 1 day
await sandbox.setAutoDeleteInterval(1440)
// Delete immediately upon stopping
await sandbox.setAutoDeleteInterval(0)
// Disable auto-delete
await sandbox.setAutoDeleteInterval(-1)
await sandbox.refreshData()
console.log(`Auto-delete: ${sandbox.autoDeleteInterval} minutes`)
Default Auto-Delete
By default, auto-delete is disabled (autoDeleteInterval = -1).
Ephemeral Sandboxes
Create sandboxes that are automatically deleted when stopped:
// Ephemeral sandbox - deleted immediately upon stopping
const ephemeralSandbox = await daytona.create({
ephemeral: true
})
// Equivalent to:
// await daytona.create({ autoDeleteInterval: 0 })
console.log(`Auto-delete: ${ephemeralSandbox.autoDeleteInterval}`) // 0
Lifecycle Configuration Examples
Development Environment
// Development sandbox with moderate lifecycle
const devSandbox = await daytona.create({
autoStopInterval: 60, // Stop after 1 hour idle
autoArchiveInterval: 1440, // Archive after 1 day stopped
autoDeleteInterval: -1, // Never auto-delete
labels: {
environment: 'development'
}
})
CI/CD Pipeline Sandbox
// Short-lived CI sandbox
const ciSandbox = await daytona.create({
autoStopInterval: 5, // Stop after 5 minutes idle
autoDeleteInterval: 60, // Delete after 1 hour stopped
labels: {
purpose: 'ci-pipeline',
pipeline_id: 'build-123'
}
})
Long-Term Research Environment
// Long-lived research sandbox
const researchSandbox = await daytona.create({
autoStopInterval: 240, // Stop after 4 hours idle
autoArchiveInterval: 0, // Maximum archive interval
autoDeleteInterval: -1, // Never auto-delete
labels: {
project: 'ml-research',
preserve: 'true'
}
})
Temporary Demo Environment
// Ephemeral demo sandbox
const demoSandbox = await daytona.create({
ephemeral: true, // Delete on stop
autoStopInterval: 120, // Stop after 2 hours
public: true, // Public preview URLs
labels: {
purpose: 'demo',
temporary: 'true'
}
})
Activity Refresh
Reset the inactivity timer to prevent auto-stop:
// Keep sandbox alive during long-running operations
await sandbox.refreshActivity()
// The auto-stop timer is now reset
What Counts as Activity?
The following actions reset the inactivity timer:
- SDK operations (file operations, process execution, etc.)
- State changes (start, stop)
- Configuration updates
- Manual activity refresh
Note: Preview URL access does NOT count as activity.
Lifecycle Interval Reference
| Parameter | Type | Default | Special Values |
|---|
autoStopInterval | number | 15 | 0 = disabled |
autoArchiveInterval | number | 10080 (7 days) | 0 = max interval |
autoDeleteInterval | number | -1 (disabled) | -1 = disabled
0 = immediate |
ephemeral | boolean | false | Sets autoDeleteInterval = 0 |
Time Conversion Helper
// Helper function to convert time units to minutes
function toMinutes(value: number, unit: 'minutes' | 'hours' | 'days'): number {
const multipliers = {
minutes: 1,
hours: 60,
days: 1440
}
return value * multipliers[unit]
}
// Examples:
const sandbox = await daytona.create({
autoStopInterval: toMinutes(2, 'hours'), // 120 minutes
autoArchiveInterval: toMinutes(3, 'days'), // 4320 minutes
autoDeleteInterval: toMinutes(7, 'days') // 10080 minutes
})
Best Practices
-
Development environments: Use moderate auto-stop (30-60 min) to save resources while maintaining convenience.
-
CI/CD sandboxes: Use aggressive auto-delete (ephemeral or short intervals) to minimize costs.
-
Production-like environments: Disable auto-delete and use long archive intervals to preserve important work.
-
Demos and testing: Use ephemeral sandboxes for temporary workloads.
-
Long-running jobs: Call
refreshActivity() periodically to prevent auto-stop during extended operations.
-
Cost optimization: Enable auto-archive and auto-delete for unused sandboxes to reduce storage costs.