Create an async factory function that creates a new Daytona 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 createDaytonaSandboxFactoryFromSandbox()
with a pre-created sandbox instead.
createDaytonaSandboxFactory(options: DaytonaSandboxOptions): AsyncDaytonaSandboxFactory| Name | Type | Description |
|---|---|---|
options | DaytonaSandboxOptions | Optional configuration for sandbox creation |
import { DaytonaSandbox, createDaytonaSandboxFactory } from "@langchain/daytona";
// Create a factory for new sandboxes
const factory = createDaytonaSandboxFactory({ language: "typescript" });
// Each call creates a new sandbox
const sandbox1 = await factory();
const sandbox2 = await factory();
try {
// Use sandboxes...
} finally {
await sandbox1.close();
await sandbox2.close();
}