VM Specs
Whenever you start a sandbox, you can specify which VM specs to use. This allows you to customize the VM to your needs. We also allow you to change the VM specs of a running sandbox on the fly, without reboot. This is useful if you want to scale up or down your sandbox dynamically based on workload needs.
Starting Sandbox with Specs
You can start a sandbox with a specific VM tier by passing the vmTier
option to the sandbox.create
method:
import { CodeSandbox, VMTier } from "@codesandbox/sdk";
const sdk = new CodeSandbox();
const sandbox = await sdk.sandbox.create({ vmTier: VMTier.Small });
You can also approximate the VM size:
const sandbox = await sdk.sandbox.create({
vmTier: VMTier.fromSpecs({ cpu: 4, memGiB: 8 }),
});
This will pick the smallest VM tier that can fit the specs you provided.
Changing VM Specs
You can change the VM specs of a running sandbox by calling the sandbox.updateTier
method:
await sandbox.updateTier(VMTier.Medium);
This will change the VM specs of the sandbox dynamically, without rebooting.
Be careful when scaling the VM specs of a running sandbox down. If you scale down the VM too much, it might not have enough resources to run your tasks and will slow to a crawl.