Home/Tools/bash-tool

createBashTool

bash-tool

Creates a bash tool environment with specified files for code execution.

by Vercel, Inc.

code-generation
v1.3.6
MIT
⚠️

This tool is currently broken

Import Failed
Cannot load from Railway service
Invalid AI SDK tool structure (missing description or execute)

Last checked: 1/16/2026, 3:45:29 AM

Interactive Playground

Test bash-tool (createBashTool) with AI-powered execution

0/2000 characters

Installation & Usage

Install this tool and use it with the AI SDK

1. Install the package

npm install bash-tool
pnpm add bash-tool
yarn add bash-tool
bun add bash-tool
deno add npm:bash-tool

2. Import the tool

import { createBashTool } from 'bash-tool';

3. Use with AI SDK

import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { createBashTool } from 'bash-tool';

const result = await generateText({
  model: openai('gpt-4o'),
  tools: { createBashTool },
  prompt: 'Your prompt here...',
});

console.log(result.text);

AI Agent Integration

How AI agents can use this tool

Use Case

Use this tool to execute bash commands and manipulate files within a sandboxed environment.

Examples

  • Create a bash environment with specific files and execute commands.

Parameters

Available configuration options

Author-provided
files
Required
Type: object

An object containing file paths as keys and file contents as values.

Schema extracted: 1/16/2026, 1:01:41 AM

Try to auto-extract schema from the package

README

bash-tool

Generic bash tool for AI agents, compatible with AI SDK.

Installation

npm install bash-tool just-bash

For full VM support, install @vercel/sandbox or another sandbox product instead of just-bash.

Usage

import { createBashTool } from "bash-tool";
import { ToolLoopAgent, stepCountIs } from "ai";

const { tools } = await createBashTool({
  files: {
    "src/index.ts": "export const hello = 'world';",
    "package.json": '{"name": "my-project"}',
  },
});

const agent = new ToolLoopAgent({
  model: yourModel,
  tools,
  // Or use just the bash tool as tools: {bash: tools.bash}
  stopWhen: stepCountIs(20),
});

const result = await agent.generate({
  prompt: "Analyze the project and create a summary report",
});

Tools

The tools object contains three tools that can be used by AI agents:

bash

Execute bash commands in the sandbox environment. For analysis agents, this may be the only tool you need to give to the agent.

Input:

  • command (string): The bash command to execute

Returns:

  • stdout (string): Standard output from the command
  • stderr (string): Standard error from the command
  • exitCode (number): Exit code of the command

readFile

Read the contents of a file from the sandbox.

Input:

  • path (string): The path to the file to read

Returns:

  • content (string): The file contents

writeFile

Write content to a file in the sandbox. Creates parent directories if needed.

Input:

  • path (string): The path where the file should be written
  • content (string): The content to write to the file

Returns:

  • success (boolean): true if the write succeeded

Advanced Usage

Upload a local directory

const { bash } = await createBashTool({
  uploadDirectory: {
    source: "./my-project",
    include: "**/*.{ts,json}", // optional glob filter
  },
});

Use @vercel/sandbox for full VM

import { Sandbox } from "@vercel/sandbox";

const sandbox = await Sandbox.create();
// Files are written to ./workspace by default
const { 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 ID
const newSandbox = await Sandbox.create();
const sandboxId = newSandbox.sandboxId;
// Store sandboxId in database, session, or return to client

// Subsequent invocations: reconnect to existing sandbox
const existingSandbox = await Sandbox.get({ sandboxId });
const { tools } = await createBashTool({ sandbox: existingSandbox });
// All previous files and state are preserved

Use a custom just-bash instance

import { Bash } from "just-bash";

const sandbox = new Bash({ cwd: "/app" });
const { tools } = await createBashTool({
  sandbox,
  destination: "/app",
});

Intercept bash commands

const { tools } = await createBashTool({
  onBeforeBashCall: ({ command }) => {
    console.log("Running:", command);
    // Optionally modify the command
    if (command.includes("rm -rf")) {
      return { command: "echo 'Blocked dangerous command'" };
    }
  },
  onAfterBashCall: ({ command, result }) => {
    console.log(`Exit code: ${result.exitCode}`);
    // Optionally modify the result
    return { result: { ...result, stdout: result.stdout.trim() } };
  },
});

Custom sandbox implementation

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 writeFile(path, content) {
    // Your implementation here
  },
};

const { tools } = await createBashTool({ sandbox: customSandbox });

AI Agent Instructions

For AI agents working with bash-tool, additional guidance is available in AGENTS.md:

cat node_modules/bash-tool/dist/AGENTS.md

License

MIT

Statistics

Downloads/month

0

GitHub Stars

0

Quality Score

0%

Bundle Size

NPM Keywords

bash
ai
tool
agent
ai-sdk
sandbox
vercel

Maintainers

cramforce(malte.ubl@gmail.com)

Frameworks

vercel-ai
createBashTool | TPMJS | TPMJS