Skip to main content

createSandbox()v4.0.426

warning

实验性包:我们保留在本通知取消之前,为了纠正糟糕的设计决策而进行重大更改的权利。

创建一个新的 Vercel Sandbox,其中安装了所有 Remotion 依赖,包括系统库、合成器和浏览器。 创建沙盒后,调用 addBundleToSandbox() 将你的 Remotion 包复制到其中。

🌐 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

create-snapshot.ts
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.

const onProgress: CreateSandboxOnProgress = async ({progress, message}) => {
  console.log(`${message} (${Math.round(progress * 100)}%)`);
};

resources?

要分配给沙箱的资源。类型继承自 @vercel/sandbox SDK。

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

每个 vCPU 获得 2048 MB 的内存。

🌐 Each vCPU gets 2048 MB of memory.

custom-resources.ts
const sandbox = await createSandbox({ resources: {vcpus: 8}, });

默认:{vcpus: 4}

🌐 Default: {vcpus: 4}.

返回值

🌐 Return value

一个 VercelSandbox 对象(一个具有 AsyncDisposable 支持的 Sandbox)。

🌐 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:

使用 sandbox.stop()

🌐 Using sandbox.stop()

完成后手动调用 sandbox.stop()

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

manual-cleanup.ts
const sandbox = await createSandbox(); // ... use the sandbox await sandbox.stop();

使用 await using

🌐 Using await using

使用 await using 在沙箱超出范围时自动停止它:

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

auto-cleanup.ts
await using sandbox = await createSandbox(); // ... use the sandbox // sandbox.stop() is called automatically

另请参阅

🌐 See also