Creating an AI Agent That Can Interact with Shells and Construct Its Own Tools
In this tutorial, we'll explore how to create an AI agent that can interact with shells like bash and construct its own tools using ChatBotKit. This capability opens up exciting possibilities, allowing agents to orchestrate their own programming environment, write specialized tools, and process large amounts of data securely and efficiently.
Shell abilities run inside lightweight, transient VMs powered by AWS Firecracker. Each conversation gets its own isolated sandbox, so commands are executed safely without any risk to your infrastructure.
Prerequisites
- A ChatBotKit account
- Basic familiarity with the Blueprint Designer
Step 1: Create a Blueprint
- In ChatBotKit, create a new blueprint for the task.
- Click on "Design" to enter the Blueprint Designer.
- Choose the "Blank" option to start with a bot and an empty skillset.
Step 2: Add Shell Abilities
ChatBotKit provides a set of shell abilities that give your agent full access to a Unix environment.
-
In the Blueprint Designer, open your skillset and search for "Install Shell Tools" (the
pack/shellability). Adding this pack installs the core shell abilities in one step:- Execute Shell Command - Run any bash command or script
- Read File from Shell Environment - Read file contents with optional line ranges
- Write File in Shell Environment - Write or modify files in the sandbox
- Import URL to Shell Environment - Download files from URLs into the sandbox
-
For scripting support, also add any of the following abilities depending on your needs:
- Execute Python Script - Run Python scripts with full library access
- Execute Node.js Script - Run JavaScript/Node.js code
- Evaluate Python Code - Quick Python code evaluation without writing a file
- Evaluate Node Code - Quick JavaScript evaluation
-
Name the bot "Shellbot" and save the blueprint.
Step 3: Add a Space for File Persistence
Shell abilities work with Spaces to persist files across conversation turns. Without a Space, files written in one turn are not available in the next.
- In the Blueprint Designer, add a new Space resource to the blueprint.
- Connect the Space to the bot. The shell abilities automatically use the connected Space as their working directory.
- This allows Shellbot to write a script in one message, then execute and refine it in subsequent messages.
Step 4: Test the Solution
- Open the Chat interface from your blueprint to start a conversation with Shellbot.
- Ask Shellbot to perform a task, such as fetching a website and extracting the page title.
- Observe how the bot generates the correct shell command, executes it, and returns the result.
- Try more advanced requests, such as writing a Python script to process data or creating a small Node.js tool.
Example prompts to try:
"Fetch the title of https://chatbotkit.com using curl""Write a Python script that sorts a list of numbers, then run it""Create a bash function to count lines in a file and test it"
Step 5: Expand the Agent's Capabilities
Shell agents can build progressively more complex tools throughout a conversation:
- Ask the agent to write a script and save it to the Space - it will persist for the session.
- Ask the agent to modify or improve the script in a follow-up message.
- Combine shell execution with other abilities (such as web fetch or file read/write) to create multi-step pipelines.
Some powerful use cases enabled by this pattern:
- Processing large datasets by writing optimized tools in Rust or Go
- Scraping and transforming web data with custom scripts
- Generating reports by combining data fetching, processing, and formatting steps
- Automating tasks that require multiple shell commands chained together
Benefits and Use Cases
- Agents can interact with a full shell in a scalable and secure way.
- The solution runs on transient VMs using AWS Firecracker, providing strong isolation between conversations.
- Agents can create specialized tools and carry over their progress throughout the conversation using Spaces.
- This capability enables scenarios where agents start with nothing and create the necessary mechanics to complete tasks.
- Agents can write tools in languages like Python, Node.js, Rust, or Go to process large amounts of data safely.
Troubleshooting
Shell commands are not executing
- Make sure at least one shell ability (such as
shell/execor thepack/shellpack) is added to your skillset. - Verify the skillset is connected to the bot in the Blueprint Designer.
Files written in one message are not visible in the next
- Connect a Space to your blueprint. Without a Space, the sandbox resets between turns and files do not persist.
Python or Node.js scripts fail with "command not found"
- Add the Execute Python Script (
shell/exec/python) or Execute Node.js Script (shell/exec/node) ability to your skillset. These abilities are separate from the base shell pack.
Command times out
- The default timeout is 60 seconds. For long-running tasks, ask the agent to use the
timeoutparameter (maximum 300 seconds / 5 minutes).
Conclusion
ChatBotKit's shell abilities let AI agents orchestrate their own programming environment and construct specialized tools on the fly. By following the steps outlined in this tutorial, you can build powerful agents that tackle complex tasks efficiently and securely. Combine shell execution with Spaces for persistence, and Python or Node.js for scripting flexibility, to unlock the full potential of agentic AI.