import { Sandbox } from "@vercel/sandbox";const sandbox = await Sandbox.create();// Files are written to ./workspace by defaultconst { tools } = await createBashTool({ sandbox, files: { "index.ts": "console.log('hello');" },});
Persistent sandbox across serverless invocations
Use Sandbox.get to reconnect to an existing sandbox by ID:
import { Sandbox } from "@vercel/sandbox";// First invocation: create sandbox and store the IDconst newSandbox = await Sandbox.create();const sandboxId = newSandbox.sandboxId;// Store sandboxId in database, session, or return to client// Subsequent invocations: reconnect to existing sandboxconst existingSandbox = await Sandbox.get({ sandboxId });const { tools } = await createBashTool({ sandbox: existingSandbox });// All previous files and state are preserved
import { createBashTool, Sandbox } from "bash-tool";const customSandbox: Sandbox = { async executeCommand(command) { // Your implementation here return { stdout: "", stderr: "", exitCode: 0 }; }, async readFile(path) { // Your implementation here return ""; }, async writeFiles(files) { // Your implementation here - files is Array<{path, content}> },};const { tools } = await createBashTool({ sandbox: customSandbox });
Skills (Experimental)
Skills are modular capabilities that extend agent functionality. Each skill is a directory containing a SKILL.md file with instructions and optional scripts.
import { experimental_createSkillTool as createSkillTool, createBashTool,} from "bash-tool";import { ToolLoopAgent } from "ai";// Discover skills and get files to uploadconst { skill, files, instructions } = await createSkillTool({ skillsDirectory: "./skills",});// Providing a bash tool with skills is optional if your skill only has a SKILL.md file// and no further files and scripts.const { tools } = await createBashTool({ files, extraInstructions: instructions,});// Use both tools with an agentconst agent = new ToolLoopAgent({ model, tools: { skill, ...tools },});