Overview
Daytona allows you to allocate specific compute resources to each sandbox. Resources are defined when creating a sandbox and determine its computational capacity.
Resource Types
Available Resources
| Resource | Type | Unit | Description |
|---|
cpu | number | Cores | Number of CPU cores allocated |
memory | number | GiB | RAM allocation in gibibytes |
disk | number | GiB | Disk space allocation in gibibytes |
gpu | number | Units | Number of GPU units allocated |
Setting Resources
Basic Configuration
Resources are specified in the resources parameter when creating a sandbox:
import { Daytona } from '@daytonaio/sdk'
const daytona = new Daytona()
const sandbox = await daytona.create({
image: 'python:3.12',
resources: {
cpu: 4, // 4 CPU cores
memory: 8, // 8 GiB RAM
disk: 50 // 50 GiB disk space
}
})
console.log(`CPU: ${sandbox.cpu} cores`)
console.log(`Memory: ${sandbox.memory} GiB`)
console.log(`Disk: ${sandbox.disk} GiB`)
GPU Allocation
For GPU-accelerated workloads:
const sandbox = await daytona.create({
image: 'tensorflow/tensorflow:latest-gpu',
resources: {
cpu: 8,
memory: 32,
disk: 100,
gpu: 1 // 1 GPU unit
}
})
console.log(`GPU: ${sandbox.gpu} units`)
Default Resources
When resources are not specified:
- Sandboxes use default resource allocations based on your organization’s configuration
- Resources can vary depending on the region and availability
// Uses default resources
const sandbox = await daytona.create({
snapshot: 'default-python'
})
console.log(`Default CPU: ${sandbox.cpu} cores`)
console.log(`Default Memory: ${sandbox.memory} GiB`)
Resource Planning
Use Case Examples
Lightweight Development
const devSandbox = await daytona.create({
resources: {
cpu: 1,
memory: 2,
disk: 10
}
})
Standard Application Testing
const testSandbox = await daytona.create({
resources: {
cpu: 2,
memory: 4,
disk: 20
}
})
Data Science Workloads
const dataScienceSandbox = await daytona.create({
image: Image.debianSlim('3.12')
.pipInstall(['pandas', 'numpy', 'scikit-learn']),
resources: {
cpu: 8,
memory: 32,
disk: 100
}
})
Machine Learning Training
const mlSandbox = await daytona.create({
image: 'tensorflow/tensorflow:latest-gpu',
resources: {
cpu: 16,
memory: 64,
disk: 200,
gpu: 2
}
})
Resizing Sandboxes
Sandbox resizing allows you to adjust resources without recreating the sandbox.
// Resize an existing sandbox
await sandbox.resize({
cpu: 8,
memory: 16,
disk: 100
})
await sandbox.refreshData()
console.log(`New CPU: ${sandbox.cpu} cores`)
console.log(`New Memory: ${sandbox.memory} GiB`)
Monitoring Resources
Check Current Allocation
const sandbox = await daytona.get('sandbox-id')
console.log('Resource Allocation:')
console.log(` CPU: ${sandbox.cpu} cores`)
console.log(` Memory: ${sandbox.memory} GiB`)
console.log(` Disk: ${sandbox.disk} GiB`)
console.log(` GPU: ${sandbox.gpu || 0} units`)
List Sandboxes with Resources
const result = await daytona.list()
for (const sandbox of result.items) {
console.log(`${sandbox.id}:`)
console.log(` CPU: ${sandbox.cpu}, Memory: ${sandbox.memory}, Disk: ${sandbox.disk}`)
}
Snapshots with Resources
When creating snapshots with specific resource requirements:
import { Daytona, Image } from '@daytonaio/sdk'
const daytona = new Daytona()
const image = Image.debianSlim('3.12')
.pipInstall(['pandas', 'numpy', 'matplotlib'])
await daytona.snapshot.create(
{
name: 'data-science-env',
image,
resources: {
cpu: 4,
memory: 16,
disk: 50
}
},
{
onLogs: console.log
}
)
// Create sandboxes from snapshot (inherits resource allocation)
const sandbox = await daytona.create({
snapshot: 'data-science-env'
})
Best Practices
-
Start small: Begin with minimal resources and scale up based on actual usage.
-
Match workload to resources:
- CPU-intensive: Increase CPU cores
- Memory-intensive: Increase RAM
- Data processing: Increase disk space
- ML/AI workloads: Add GPU resources
-
Use cost-effective configurations: Right-size resources to avoid over-provisioning.
-
Monitor and adjust: Use sandbox resizing to optimize resources over time.
-
Snapshot resource templates: Create snapshots with different resource profiles for common use cases.
Resource Limits
Resource availability may be subject to:
- Organization quotas
- Region availability
- Plan limitations
Contact your organization administrator or Daytona support for quota increases.