Learn how to build your first sandbox using the Decentra Sandbox Platform API.
Using the TypeScript SDK
The simplest approach to setting up a sandbox is through our official TypeScript SDK.
1
Create a sandbox (TypeScript SDK)
importSandboxSDKfrom'@avmcodes/sandbox-sdk';constclient=newSandboxSDK({apiKey:process.env['SANDBOX_SDK_API_KEY'],});// Create a sandbox with default settingsconstsandbox=awaitclient.sandboxes.create({name:'My First Sandbox',});console.log('Sandbox created:',sandbox.id);
2
Customizing Resources
You’re able to adjust processor and memory resources as required.
constsandbox=awaitclient.sandboxes.create({name:'High Performance Sandbox',resources:{cpus:4,memory:2048,// Memory in MiB},});
3
Using a Custom Docker Image
A standard Decentra sandbox image is used automatically, but you can point to a different image if needed.
You can mount persistent storage to retain data across sandbox sessions.
constsandbox=awaitclient.sandboxes.create({name:'Sandbox with Volume',volumes: [{volume_id:'vol_x1y2z3a4b5c6d7e8',mount_path:'/data',}, ],});
5
Setting Environment Variables
Environment variables can be injected into your sandbox configuration.
constsandbox=awaitclient.sandboxes.create({name:'Sandbox with Env Vars',env_vars:{API_KEY:'your-api-key',DEBUG:'true',},});
Response Structure
The create() method returns a SandboxCreateResponse object:
constsandbox=awaitclient.sandboxes.create({name:'My First Sandbox',resources:{cpus:2,memory:512,},});// sandbox contains:console.log(sandbox.id);// "sbx_x1y2z3a4b5c6d7e8"console.log(sandbox.name);// "My First Sandbox"console.log(sandbox.status);// "creating"console.log(sandbox.cpu);// 2console.log(sandbox.memory);// 512console.log(sandbox.created_at);// "2024-01-15T12:00:00Z"console.log(sandbox.volumes);// Array of mounted volumes (if any)