Create a backend factory that reuses an existing Deno Sandbox.
This allows multiple agent invocations to share the same sandbox, avoiding the startup overhead of creating new sandboxes.
Important: You are responsible for managing the sandbox lifecycle
(calling close() when done).
createDenoSandboxFactoryFromSandbox(sandbox: DenoSandbox): BackendFactory| Name | Type | Description |
|---|---|---|
sandbox* | DenoSandbox | An existing DenoSandbox instance (must be initialized) |
import { createDeepAgent, createFilesystemMiddleware } from "deepagents";
import { DenoSandbox, createDenoSandboxFactoryFromSandbox } from "@langchain/deno";
// Create and initialize a sandbox
const sandbox = await DenoSandbox.create({ memory: "1GiB" });
try {
const agent = createDeepAgent({
model: new ChatAnthropic({ model: "claude-sonnet-4-20250514" }),
systemPrompt: "You are a coding assistant.",
middlewares: [
createFilesystemMiddleware({
backend: createDenoSandboxFactoryFromSandbox(sandbox),
}),
],
});
await agent.invoke({ messages: [...] });
} finally {
await sandbox.close();
}