Skip to main content
When the sandbox instance is not currently needed but you need to be able to resume it at any time later, you can refer to the documentation to manually pause and resume sandbox instances. The “Auto Pause and Resume” feature allows your sandbox instance to automatically pause after timeout and resume when needed. When you attempt to perform operations (such as executing commands, running code, or file operations) on a paused sandbox, it will automatically resume without manual intervention.

Enable Auto Pause

You can enable the auto pause feature by setting the auto_pause parameter to true when creating a sandbox instance. The sandbox instance will automatically pause after timeout and can be resumed later.
Note: The resumed sandbox instance will still have the auto pause feature enabled and will automatically pause again after timeout.
import { Sandbox } from 'novita-sandbox/code-interpreter';

const sandbox = await Sandbox.create(
    {
        timeoutMs: 5_000,
        autoPause: true
    },
);
console.log('Sandbox created', sandbox.sandboxId)

console.log('Waiting for 10 seconds...')
await new Promise(resolve => setTimeout(resolve, 10000));

const resumedSandbox = await Sandbox.connect(sandbox.sandboxId)
console.log('Sandbox resumed', resumedSandbox.sandboxId)

await sandbox.kill()

Enable Auto Resume

You can enable the auto resume feature by setting the auto_resume key in metadata to true when creating a sandbox instance. Once enabled, when you attempt to operate on a paused sandbox (such as executing commands, running code, file operations, etc.), the sandbox will automatically resume.
Note: The default timeout for the resumed sandbox is 5 minutes. You can update the sandbox timeout using the setTimeout or set_timeout method.
import { Sandbox } from 'novita-sandbox/code-interpreter';

const sandbox = await Sandbox.create(
    {
        metadata:{"auto_resume": "true"}
    }
);
console.log('Sandbox created', sandbox.sandboxId)

await sandbox.betaPause()
console.log('Sandbox paused', sandbox.sandboxId)

const result = await sandbox.commands.run('ls -al')
console.log('Command result', result)

await sandbox.kill()