Back to Remotion

createSandbox()

packages/docs/docs/vercel/create-sandbox.mdx

4.0.4873.2 KB
Original Source

createSandbox()<AvailableFrom v="4.0.426" />

:::warning Experimental package: We reserve the right to make breaking changes in order to correct bad design decisions until this notice is gone. :::

Creates a new Vercel Sandbox with all Remotion dependencies installed, including system libraries, the compositor, and a browser.
After creating the sandbox, call addBundleToSandbox() to copy your Remotion bundle into it.

Example

ts
// @module: es2022
// @target: es2022
import {addBundleToSandbox, createSandbox} from '@remotion/vercel';
import type {CreateSandboxOnProgress} from '@remotion/vercel';
// ---cut---
const sandbox = await createSandbox({
  onProgress: async ({progress, message}) => {
    console.log(`${message} (${Math.round(progress * 100)}%)`);
  },
});

await addBundleToSandbox({
  sandbox,
  bundleDir: '/path/to/bundle',
});

// ... use the sandbox

await sandbox.stop();

Arguments

An object with the following properties:

onProgress?

A callback that receives progress updates during sandbox creation.

ts
import type {CreateSandboxOnProgress} from '@remotion/vercel';
// ---cut---
const onProgress: CreateSandboxOnProgress = async ({progress, message}) => {
  console.log(`${message} (${Math.round(progress * 100)}%)`);
};

resources?

The resources to allocate to the sandbox. The type is inherited from the @vercel/sandbox SDK.

Each vCPU gets 2048 MB of memory.

ts
// @module: es2022
// @target: es2022
import {createSandbox} from '@remotion/vercel';
// ---cut---
const sandbox = await createSandbox({
  resources: {vcpus: 8},
});

Default: {vcpus: 4}.

timeoutInMilliseconds?<AvailableFrom v="4.0.452" />

The maximum time allowed for the sandbox to be created, in milliseconds. If exceeded, sandbox creation is aborted.

Default: 300000 (5 minutes).

Return value

A VercelSandbox object (a Sandbox with AsyncDisposable support).

Stopping the sandbox

When you are done with the sandbox, you need to stop it to free resources. There are two ways to do this:

Using sandbox.stop()

Manually call sandbox.stop() when you are done:

ts
// @module: es2022
// @target: es2022
import {createSandbox} from '@remotion/vercel';
// ---cut---
const sandbox = await createSandbox();

// ... use the sandbox

await sandbox.stop();

Using await using

Use await using to automatically stop the sandbox when it goes out of scope:

ts
// @module: es2022
// @target: es2022
import {createSandbox} from '@remotion/vercel';
// ---cut---
await using sandbox = await createSandbox();

// ... use the sandbox
// sandbox.stop() is called automatically

See also