Secure, sandboxed bash tool access for AI agents
Project description
Safe, guardrailed shell access for AI agents.
safeshell gives your LLM agents (LangChain, PydanticAI, or custom) the power to run shell commands with built-in safety rails. While traditional subprocess wrappers are unsafe and Docker containers are heavy, safeshell provides a graduated security model that works instantly in any Python environment. It features built-in protection against dangerous patterns like rm -rf /, curl | sh, fork bombs, and more.
Roadmap
See our Detailed Roadmap for upcoming features like Windows support, Daemon mode, and OS-level sandboxing (macOS/Linux).
Use Cases
- Agentic coding assistants: Allow agents to run
ls,cat,grep, andmvto modify codebases safely. - Data analysis pipelines: Let LLMs explore CSV/JSON files using
head,tail,jq, andawkwithout risking system stability. - Automated DevOps: Create restricted agents that can restart specific services (via allowlist) but cannot modify system configuration.
- Educational tools: Provide a safe shell environment for students to practice bash commands.
Features
- Security-first: Blocks 20+ dangerous command patterns (
rm -rf /, fork bombs, etc.) out of the box. - Instant startup: No Docker or VMs required. Works anywhere Python runs.
- Three security levels:
STANDARD: Blocks known exploits (Default).PARANOID: Allowlist-only (e.g., only allowlsandgrep).PERMISSIVE: Logging-only for trusted environments.
- Read-only mode: Agents can "modify" files in a temporary overlay without touching your actual disk.
- Dynamic tool discovery: Automatically generates LLM-optimized prompts based on available tools (
grep,jq,git, etc.). - Framework-agnostic: First-class support for generic Python, LangChain, and PydanticAI.
Installation
pip install safeshell
Quick Start
import asyncio
from safeshell import create_sandbox_tool, SecurityViolation
async def main():
# Create a sandboxed toolkit
toolkit = await create_sandbox_tool(source="./my_project")
# Run commands safely
result = await toolkit.bash("ls -la")
print(result.stdout)
# Dangerous commands are blocked automatically
try:
await toolkit.bash("rm -rf /")
except SecurityViolation as e:
print(f"Blocked: {e}")
await toolkit.close()
asyncio.run(main())
Integrations
LangChain
Safeshell creates compatible StructuredTool objects for LangChain agents.
from safeshell import create_sandbox_tool
from safeshell.integrations.langchain import create_langchain_tools
toolkit = await create_sandbox_tool()
tools = create_langchain_tools(toolkit) # Returns dict of tools
# Use with any LangChain agent
agent = create_react_agent(llm, list(tools.values()))
PydanticAI
Use the create_pydantic_ai_tools helper to inject tools into PydanticAI agents.
from safeshell import create_sandbox_tool
from safeshell.integrations.pydantic_ai import create_pydantic_ai_tools
toolkit = await create_sandbox_tool()
pydantic_tools = create_pydantic_ai_tools(toolkit)
# Register with your agent
for tool in pydantic_tools:
agent.tool(tool)
Blocked Patterns
Safeshell blocks 20+ dangerous command patterns, including:
| Category | Pattern | Description |
|---|---|---|
| Filesystem | rm -rf / |
Recursive delete of root |
mkfs |
Filesystem creation | |
| RCE | curl | sh |
Pipe remote script to shell |
wget | python |
Pipe remote script to Python | |
| Resource | :(){ :|:& };: |
Fork bomb |
yes | |
Infinite output pipe | |
| Privilege | sudo |
Sudo commands |
su - |
Switch user | |
| Disk | dd of=/dev/sda |
Direct disk write |
chmod 777 / |
Dangerous permissions |
Contributing
We welcome contributions! Please follow these steps:
- Fork the repository.
- Install dependencies:
pip install -e ".[dev]"
- Run tests:
make test
- Submit a Pull Request.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file safeshell-1.0.0.tar.gz.
File metadata
- Download URL: safeshell-1.0.0.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97059be1a0ae053e2a04a90250003e89b7a4b08a1fc4befc0b711c89af7de876
|
|
| MD5 |
2c5db6f7feb5605e12de2d92aa70f50c
|
|
| BLAKE2b-256 |
5f8ebc3680b4a1967c28c8a0eec0d12d548f8294a053bccd54ea8f5f6612205b
|
Provenance
The following attestation bundles were made for safeshell-1.0.0.tar.gz:
Publisher:
publish.yml on Khadka-Bishal/safeshell
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
safeshell-1.0.0.tar.gz -
Subject digest:
97059be1a0ae053e2a04a90250003e89b7a4b08a1fc4befc0b711c89af7de876 - Sigstore transparency entry: 820494723
- Sigstore integration time:
-
Permalink:
Khadka-Bishal/safeshell@13e4b5c295bfb911732d95b41a3716cf6be01ba8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Khadka-Bishal
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@13e4b5c295bfb911732d95b41a3716cf6be01ba8 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file safeshell-1.0.0-py3-none-any.whl.
File metadata
- Download URL: safeshell-1.0.0-py3-none-any.whl
- Upload date:
- Size: 18.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5882b784907a8f20ea807d7b7fb5f42a73cb66aa15045c78bf7e5dbb496b7c99
|
|
| MD5 |
7c285ad32eafd0eac6fd8ca99f595b67
|
|
| BLAKE2b-256 |
b7c25e988cecb62a817b64a5bbf9f768fd815c4d48cdeb7e8371031e894af0ee
|
Provenance
The following attestation bundles were made for safeshell-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on Khadka-Bishal/safeshell
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
safeshell-1.0.0-py3-none-any.whl -
Subject digest:
5882b784907a8f20ea807d7b7fb5f42a73cb66aa15045c78bf7e5dbb496b7c99 - Sigstore transparency entry: 820494725
- Sigstore integration time:
-
Permalink:
Khadka-Bishal/safeshell@13e4b5c295bfb911732d95b41a3716cf6be01ba8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Khadka-Bishal
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@13e4b5c295bfb911732d95b41a3716cf6be01ba8 -
Trigger Event:
workflow_dispatch
-
Statement type: