createModalSandboxFactory(options: ModalSandboxOptions): AsyncModalSandboxFactory| Name | Type | Description |
|---|---|---|
options | ModalSandboxOptions | Optional configuration for sandbox creation |
import { ModalSandbox, createModalSandboxFactory } from "@langchain/modal";
// Create a factory for new sandboxes
const factory = createModalSandboxFactory({ imageName: "python:3.12-slim" });
// Each call creates a new sandbox
const sandbox1 = await factory();
const sandbox2 = await factory();
try {
// Use sandboxes...
} finally {
await sandbox1.close();
await sandbox2.close();
}Create an async factory function that creates a new Modal Sandbox per invocation.
Each call to the factory will create and initialize a new sandbox. This is useful when you want fresh, isolated environments for each agent invocation.
Important: This returns an async factory. For use with middleware that
requires synchronous BackendFactory, use createModalSandboxFactoryFromSandbox()
with a pre-created sandbox instead.