class ModalSandboxModal Sandbox backend for deepagents.
Extends BaseSandbox to provide command execution, file operations, and
sandbox lifecycle management using Modal's serverless infrastructure.
import { ModalSandbox } from "@langchain/modal";
// Create and initialize a sandbox
const sandbox = await ModalSandbox.create({
imageName: "python:3.12-slim",
timeout: 600,
});
try {
// Execute commands
const result = await sandbox.execute("python --version");
console.log(result.output);
} finally {
// Always cleanup
await sandbox.close();
}
import { createDeepAgent } from "deepagents";
import { ModalSandbox } from "@langchain/modal";
const sandbox = await ModalSandbox.create();
const agent = createDeepAgent({
model: new ChatAnthropic({ model: "claude-sonnet-4-20250514" }),
systemPrompt: "You are a coding assistant with sandbox access.",
backend: sandbox,
});