Node.js VFS Sandbox backend for deepagents.
Provides an in-memory virtual file system for agent operations, allowing agents to read/write files without affecting the real filesystem.
This implementation uses node-vfs-polyfill which implements the upcoming Node.js VFS feature. Files are stored in-memory using the VFS, and when command execution is needed, files are synced to a temp directory.
import { VfsSandbox } from "@langchain/node-vfs";
// Create and initialize a VFS sandbox
const sandbox = await VfsSandbox.create({
initialFiles: {
"/src/index.js": "console.log('Hello')",
},
});
try {
// Execute commands
const result = await sandbox.execute("node src/index.js");
console.log(result.output);
} finally {
await sandbox.stop();
}
import { createDeepAgent } from "deepagents";
import { VfsSandbox } from "@langchain/node-vfs";
const sandbox = await VfsSandbox.create();
const agent = createDeepAgent({
model: new ChatAnthropic({ model: "claude-sonnet-4-20250514" }),
systemPrompt: "You are a coding assistant with VFS access.",
backend: sandbox,
});class VfsSandboxDownload files from the sandbox.
Edit a file by replacing string occurrences.
Uses downloadFiles() to read, performs string replacement in TypeScript, then uploadFiles() to write back. No runtime needed on the sandbox host.
Execute a command in the sandbox.
Commands are run using /bin/bash -c in the sandbox working directory.
When using VFS mode, files are synced to a temp directory before execution
and synced back after.
Structured glob matching returning FileInfo objects.
Overrides BaseSandbox.globInfo() to normalize paths with a leading /
so they resolve correctly in the temp execution directory.
Search for a literal text pattern in files.
Overrides BaseSandbox.grepRaw() to normalize paths with a leading /
so they resolve correctly in the temp execution directory.
Initialize the VFS sandbox.
This method sets up the virtual file system and populates it with any initial files specified in the options.
List files and directories in the specified directory.
Overrides BaseSandbox.lsInfo() to normalize paths with a leading /
so they resolve correctly in the temp execution directory.
Read file content as raw FileData.
Uses downloadFiles() directly — no runtime needed on the sandbox host.
Stop the sandbox and release all resources.
Cleans up the temp directory used for command execution.
Upload files to the sandbox.
Files are written to the VFS. Parent directories are created automatically if they don't exist.
Create and initialize a new VfsSandbox in one step.
This is the recommended way to create a sandbox. It combines construction and initialization into a single async operation.