SDK
Hibernate

Hibernate

By default all Sandboxes hibernate automatically, but you can choose to explicitly hibernate as well. This will save the memory state of the sandbox, so it will resume from the same state when you start it again.

const sandbox = await sdk.sandboxes.resume('sandbox-id')
 
await sdk.sandboxes.hibernate(sandbox.id);

When creating or restarting a sandbox, you can also set a hibernation timeout between 1 minute and 24 hours. By default this timeout is 5 minutes for free users, and 30 minutes for paid users.

import { CodeSandbox } from '@codesandbox/sdk'
const sdk = new CodeSandbox();
 
const sandbox = await sdk.sandboxes.create({
  type: 'template',
  hibernationTimeoutSeconds: 60 * 60 * 1 // 1 hour
});

When you set a hibernation timeout, the sandbox will hibernate after the specified period of inactivity (no calls from the SDK). While the SDK remains connected, we recommend either explicitly hibernating the sandbox or disconnecting from it when you're done using it. Resuming only takes a few seconds, so you can be aggressive with hibernation to conserve resources.

💡

If you resume a Sandbox while it's entering hibernation, it will finish creating the snapshot before resuming. This does mean that there can be some inconsistency in resume times if you try to restart your Sandboxes too soon after telling them to hibernate.