Skip to main content

AgentShell — run CLI coding agents from Python

Agent Shell

Agent Shell is a light weight abstraction for executing a cli coding agent headlessly and returning the output that can be used programatically as a unified contract

Features

  • One unified contract — the same execute, stream, health_check, and list_models API across every agent; swap the backend without changing consuming code.
  • Seven CLI agents — Claude Code, OpenCode, Copilot CLI, Codex, Pi, Cursor, and Grok behind a common adapter protocol.
  • Execute or stream — get one AgentResponse (raises AgentExecutionError on a failed run), or async-iterate normalized StreamEvents with optional thinking/reasoning.
  • Composable execution policy — preserve native execution by default, or opt into Linux PID namespace isolation without changing an agent adapter.
  • Session resumption — continue any conversation by passing back its session_id.
  • Normalized cost & tokens — consistent cost and output_tokens (reasoning included) regardless of how each CLI reports them.
  • Model discovery — retrieve the exact account/workspace-aware model strings accepted by each CLI, without inference calls, SDK dependencies, or static catalogs.
  • Health checks — confirm an agent + model combination actually works before you rely on it, read from the event stream rather than unreliable exit codes.
  • Portable tool control — one canonical allow/deny vocabulary (bash, edit, read, web_search, web_fetch) translated to each CLI's own tool names.
  • Unified MCP management — register, remove, and list MCP servers across agents through a single API.
  • Package management — install/register, list, and remove harness packages through a shared API, with Pi as the first supported agent.
  • Async & dependency-free — pure asyncio, zero runtime dependencies, Python 3.12+.

Installation

uv add agent-shell-py

or with pip:

pip install agent-shell-py

Agent skills

The repository includes reusable skills that teach coding agents how to use AgentShell:

  • invoking-cli-agents — invoke, stream, resume, and restrict CLI agents.
  • delegating-code-review — delegate an independent code review through AgentShell.

Install them interactively with the Vercel Skills CLI:

npx skills add ScottRBK/agent-shell

Or install both skills globally for every coding agent supported by AgentShell:

npx skills add ScottRBK/agent-shell --global \
  --skill '*' \
  --agent claude-code opencode github-copilot codex pi cursor grok \
  --yes

Install only the core AgentShell skill with:

npx skills add ScottRBK/agent-shell --skill invoking-cli-agents

The skills provide agent instructions. Install agent-shell-py and the chosen coding-agent CLIs separately.

Examples

Execute

from agent_shell.shell import AgentShell
from agent_shell.models.agent import AgentType

shell = AgentShell(agent_type=AgentType.CLAUDE_CODE)

response = await shell.execute(
    cwd="/path/to/project",
    prompt="Can you tell me about this project?",
    allowed_tools=["Read", "Glob", "Grep"],
    model="sonnet",
)

print(response.response)
print(f"Cost: ${response.cost:.4f}")
print(f"Output tokens: {response.output_tokens}")  # billed output, reasoning included
print(f"Session: {response.session_id}")

# Resume the conversation using the session_id
follow_up = await shell.execute(
    cwd="/path/to/project",
    prompt="Now refactor the auth module based on your findings",
    allowed_tools=["Read", "Edit", "Bash"],
    model="sonnet",
    session_id=response.session_id,
)

output_tokens is a cost measure: the billed output-token count, which includes reasoning tokens (they are billed at the output rate). It is reported consistently across all adapters.

See more examples for isolation and execution hosts, failure handling, streaming, model discovery, health checks, tool restrictions, MCP servers, packages, and logging.

Guides

  • Nix — reproducible dev shell, build and checks from uv.lock, plus nix-build / nix-shell entry points for Nix without flakes enabled.

Metadata

Release files for agent-shell-py 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agent-shell-py 0.5.1
File Size Uploaded Provenance Actions
agent_shell_py-0.5.1.tar.gz 811.0 kB With provenance Details for agent_shell_py-0.5.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for agent-shell-py 0.5.1
File Interpreter ABI Platform Actions
agent_shell_py-0.5.1-py3-none-any.whl Python 3 none any Details for agent_shell_py-0.5.1-py3-none-any.whl

Total release size: 932.8 kB

Release files / agent_shell_py-0.5.1.tar.gz

Download URL agent_shell_py-0.5.1.tar.gz
Size 811.0 kB
Tags Source
SHA-256 checksum
How to use checksums
08c5a24c2227182b701c9c072b3ed24164aac9f6989a60dd6f11062a7dc7f5ec
BLAKE2b-256 checksum
How to use checksums
55c05fcf75450b290cfcd0b54fb9b0cc743f28b0fd8c71d18f427d6c3b320f26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / agent_shell_py-0.5.1-py3-none-any.whl

Download URL agent_shell_py-0.5.1-py3-none-any.whl
Size 121.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bc447ed22553634f1c1fbde5c67efe33c8209c814c31164fa5bb13576e26e493
BLAKE2b-256 checksum
How to use checksums
cf80a14bffa3e4fb6801cddc16886f246843c5e87a78a22969f5a880770614e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Security for agent-shell-py 0.5.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for agent_shell_py-0.5.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page