Creating your first Volume
Learn how to set up persistent volumes and connect them to your sandboxes.
Using the TypeScript SDK
1
Create a Volume
import SandboxSDK from '@dvmcodes/sandbox-sdk';
const client = new SandboxSDK({
apiKey: process.env['SANDBOX_SDK_API_KEY'],
});
// Create a volume with default size (10Gi)
const volume = await client.volumes.create({
name: 'my-persistent-storage',
});
console.log('Volume created:', volume.id);
console.log('Volume name:', volume.name);
console.log('Volume size:', volume.size);
console.log('Volume status:', volume.status);2
Verify the Volume Exists
// List all volumes
const volumesResponse = await client.volumes.list();
// Find your volume
const myVolume = volumesResponse.data.find(
v => v.name === 'my-persistent-storage'
);
if (myVolume) {
console.log('Volume found:', myVolume.id);
console.log('Status:', myVolume.status); // Should be "Bound" when ready
} else {
console.log('Volume not found');
}3
Create a Sandbox with the Volume
// Create a sandbox with the volume mounted at /data
const sandbox = await client.sandboxes.create({
name: 'Sandbox with Persistent Storage',
volumes: [
{
volume_id: volume.id,
mount_path: '/data', // Custom mount point
},
],
resources: {
cpus: 2,
memory: 512,
},
});
console.log('Sandbox created:', sandbox.id);
console.log('Volumes mounted:', sandbox.volumes);4
Download Something Heavy
// Clone a large repository to the mounted volume
const result = await client.sandboxes.execute(sandbox.id, {
command: 'cd /data && git clone --depth 1 https://github.com/torvalds/linux.git',
timeout: 300, // 5 minutes for large downloads
});
if (result.status === 'completed' && result.exit_code === 0) {
console.log('Repository cloned successfully!');
console.log('Output:', result.stdout);
} else {
console.error('Clone failed:', result.stderr);
}5
Verify Data Persistence
// List files in the mounted volume
const listResult = await client.sandboxes.execute(sandbox.id, {
command: 'ls -lh /data',
working_dir: '/data',
});
console.log('Files on volume:', listResult.stdout);
// Check the size of what we downloaded
const sizeResult = await client.sandboxes.execute(sandbox.id, {
command: 'du -sh /data/linux 2>/dev/null || echo "Directory not found"',
});
console.log('Downloaded size:', sizeResult.stdout);Complete Example
import SandboxSDK from '@dvmcodes/sandbox-sdk';
const client = new SandboxSDK({
apiKey: process.env['SANDBOX_SDK_API_KEY'],
});
async function createVolumeAndSandbox() {
// 1. Create a volume
console.log('Creating volume...');
const volume = await client.volumes.create({
name: 'my-dataset-storage',
size: '20Gi', // Larger size for big datasets
});
console.log(`Volume created: ${volume.id}`);
// 2. Wait a moment for volume to be ready
await new Promise(resolve => setTimeout(resolve, 2000));
// 3. Verify volume exists
const volumesResponse = await client.volumes.list();
const foundVolume = volumesResponse.data.find(v => v.id === volume.id);
if (!foundVolume) {
throw new Error('Volume not found after creation');
}
console.log(`Volume verified: ${foundVolume.status}`);
// 4. Create sandbox with volume mounted
console.log('Creating sandbox with volume...');
const sandbox = await client.sandboxes.create({
name: 'Data Processing Sandbox',
volumes: [
{
volume_id: volume.id,
mount_path: '/workspace', // Custom mount point
},
],
resources: {
cpus: 4,
memory: 2048,
},
});
console.log(`Sandbox created: ${sandbox.id}`);
// 5. Download a large dataset (example: TensorFlow models)
console.log('Downloading large dataset...');
const downloadResult = await client.sandboxes.execute(sandbox.id, {
command: 'cd /workspace && wget -q --show-progress https://github.com/tensorflow/tensorflow/archive/refs/heads/master.zip -O tensorflow.zip',
timeout: 600, // 10 minutes
});
if (downloadResult.status === 'completed') {
console.log('Download completed!');
console.log('Exit code:', downloadResult.exit_code);
}
// 6. Verify the download
const verifyResult = await client.sandboxes.execute(sandbox.id, {
command: 'ls -lh /workspace/tensorflow.zip',
});
console.log('File info:', verifyResult.stdout);
return { volume, sandbox };
}
// Run the example
createVolumeAndSandbox()
.then(({ volume, sandbox }) => {
console.log('Success!');
console.log(`Volume ID: ${volume.id}`);
console.log(`Sandbox ID: ${sandbox.id}`);
})
.catch(console.error);Customizing Volume Size
Using Multiple Volumes
Response Structure
Parameters
Volume Status
Best Practices
Next Steps
Last updated
