A sandboxed bash interpreter for AI agents.
from bashkit import BashTool
tool = BashTool()
result = tool.execute_sync("echo 'Hello, World!'")
print(result.stdout) # Hello, World!- Sandboxed execution — all commands run in-process with a virtual filesystem, no containers needed
- 100+ built-in commands — echo, cat, grep, sed, awk, jq, curl, find, and more
- Full bash syntax — variables, pipelines, redirects, loops, functions, arrays
- Resource limits — protect against infinite loops and runaway scripts
- Framework integrations — LangChain, PydanticAI, and Deep Agents
pip install bashkit
# With framework support
pip install 'bashkit[langchain]'
pip install 'bashkit[pydantic-ai]'import asyncio
from bashkit import Bash
async def main():
bash = Bash()
# Simple command
result = await bash.execute("echo 'Hello, World!'")
print(result.stdout) # Hello, World!
# Pipeline
result = await bash.execute("echo -e 'banana\\napple\\ncherry' | sort")
print(result.stdout) # apple\nbanana\ncherry
# Virtual filesystem persists between calls
await bash.execute("echo 'data' > /tmp/file.txt")
result = await bash.execute("cat /tmp/file.txt")
print(result.stdout) # data
asyncio.run(main())from bashkit import BashTool
tool = BashTool()
result = tool.execute_sync("echo 'Hello!'")
print(result.stdout)bash = Bash(
username="agent", # Custom username (whoami)
hostname="sandbox", # Custom hostname
max_commands=1000, # Limit total commands
max_loop_iterations=10000, # Limit loop iterations
)BashTool is a convenience wrapper specifically designed for AI agents. It wraps Bash and adds LLM tool metadata (schema, description, system prompt) needed by tool-use protocols. Use this when integrating with LangChain, PydanticAI, or similar agent frameworks.
from bashkit import BashTool
tool = BashTool()
print(tool.input_schema()) # JSON schema for LLM tool-use
print(tool.system_prompt()) # Token-efficient prompt
result = await tool.execute("echo 'Hello!'")Compose multiple tools into a single bash-scriptable interface:
from bashkit import ScriptedTool
tool = ScriptedTool("api")
tool.add_tool("greet", "Greet a user", callback=lambda p, s=None: f"hello {p.get('name', 'world')}")
result = tool.execute_sync("greet --name Alice")
print(result.stdout) # hello Alicefrom bashkit.langchain import create_bash_tool
bash_tool = create_bash_tool()
# Use with any LangChain agentfrom bashkit.pydantic_ai import create_bash_tool
bash_tool = create_bash_tool()
# Use with any PydanticAI agentCompose Python callbacks as bash builtins. An LLM writes a single bash script that pipes, loops, and branches across all registered tools.
from bashkit import ScriptedTool
def get_user(params, stdin=None):
return '{"id": 1, "name": "Alice"}'
tool = ScriptedTool("api")
tool.add_tool("get_user", "Fetch user by ID",
callback=get_user,
schema={"type": "object", "properties": {"id": {"type": "integer"}}})
result = tool.execute_sync("get_user --id 1 | jq -r '.name'")
print(result.stdout) # Alice- Sandboxed, in-process execution: All commands run in isolation with a virtual filesystem
- 100+ built-in commands: echo, cat, grep, sed, awk, jq, curl, find, and more
- Full bash syntax: Variables, pipelines, redirects, loops, functions, arrays
- Resource limits: Protect against infinite loops and runaway scripts
execute(commands: str) -> ExecResult— execute commands asynchronouslyexecute_sync(commands: str) -> ExecResult— execute commands synchronouslyreset()— reset interpreter statedescription() -> str— tool description for LLM integrationhelp() -> str— detailed documentationinput_schema() -> str— JSON input schemaoutput_schema() -> str— JSON output schema
Convenience wrapper for AI agents. Inherits all execution methods from Bash, plus:
system_prompt() -> str— token-efficient system prompt for LLM integration
stdout: str— standard outputstderr: str— standard errorexit_code: int— exit code (0 = success)error: Optional[str]— error message if execution failedsuccess: bool— True if exit_code == 0to_dict() -> dict— convert to dictionary
add_tool(name, description, callback, schema=None)— register a toolexecute(script: str) -> ExecResult— execute script asynchronouslyexecute_sync(script: str) -> ExecResult— execute script synchronouslyenv(key: str, value: str)— set environment variable
Bashkit is built on top of Bashkit core, a bash interpreter written in Rust. The Python package provides a native extension for fast, sandboxed execution without spawning subprocesses or containers.
MIT