Sandboxed bash interpreter for Python. Native bindings to the bashkit Rust core for fast, in-process execution with a virtual filesystem.
Sandboxed execution in-process, without containers or subprocess orchestration
Full bash syntax: variables, pipelines, redirects, loops, functions, and arrays
164 built-in commands including grep , sed , awk , jq , curl , and find
Persistent interpreter state across calls, including variables, cwd, and VFS contents
Direct virtual filesystem APIs, constructor mounts, and live host mounts
Snapshot and restore support on Bash and BashTool
AI integrations for LangChain, PydanticAI, and Deep Agents
Windows 11 Smart App Control
If importing the native module fails with An Application Control policy has blocked this file , PondGuard's reported workaround is to pin bashkit==0.20.0 and run tests with python -m pytest . Keep Smart App Control enabled. The pin was verified on the reporter's machine; both 0.20.0 and 0.20.1 Windows modules lack embedded Authenticode signatures, so other machines may make a different trust decision. python -m pytest avoids a blocked launcher but cannot load a blocked native module. See the Windows reproduction, evidence, and workaround guide .
max_commands and the other limits apply per execute() call. Each Bash instance also has session-wide caps that count across calls: 1,000 execute() calls ( max_exec_calls ) and 100,000 commands ( max_session_commands ). Raise them for long agent sessions; snapshots carry the counts and reset() clears them.
Embedded Python and TypeScript
Native wheels include both runtimes, disabled by default. Enable only those your application needs:
LangChain's BashkitTool and deepagents' middleware/backend accept the same flags. Runtime flags survive reset() ; supply them explicitly when restoring with BashTool.from_snapshot() or BashTool.from_snapshot_keyed() .
on_output is optional and fires during execution with chunked (stdout, stderr) pairs. Chunks are not line-aligned or exact terminal interleaving, but concatenating all callback chunks matches the final ExecResult.stdout and ExecResult.stderr . The handler must be synchronous; async def callbacks and callbacks that return awaitables are rejected.
Direct Methods on Bash and BashTool
The same direct filesystem helpers are available on BashTool() .
Native Extension Interop
to_capsule() / from_capsule() exchange a versioned stable ABI handle so separate PyO3 extensions do not need to bashkit's internal Rust object layout. Native extensions should depend on bashkit with the interop feature and use bashkit::interop::fs .
Pre-Initialized Files
Real Filesystem Mounts
curl , wget , and http are gated behind an explicit allowlist. Without a network= kwarg outbound HTTP is disabled (the secure default). Pass an explicit allowlist or allow_all=True to opt in:
network= is also accepted by BashTool(...) and persists across reset() and from_snapshot(...) . An explicit network={"allow": []} blocks every URL but is distinct from omitting network= entirely.
Inject per-host credentials transparently so scripts never see the real secret. Two modes are supported (mirroring the Rust BashBuilder::credential and BashBuilder::credential_placeholder APIs):
Each credential dict accepts kind: "bearer" ( token ), kind: "header" ( name , value ), or kind: "headers" (a list of (name, value) pairs). Injected headers overwrite script-provided headers with the same name to prevent credential spoofing. Phase 2 of #1348 covers the credential surface; request callbacks and bot-auth ship in follow-ups.
Use execute_or_throw() and execute_sync_or_throw() when you want failures surfaced as exceptions instead of inspecting exit_code manually.
cancel() sets a sticky flag that causes every future execute() to fail immediately with "execution cancelled" . Call clear_cancel() after the cancelled execution finishes to restore the instance for reuse, this preserves all VFS state. Use reset() only when you want to discard VFS and shell state entirely.
BashTool exposes the same cancel() , clear_cancel() , and reset() methods.
ShellState is a read-only snapshot for prompt rendering and inspection. It is a Python-friendly inspection view rather than a full Rust-shell mirror, and fields like env , variables , and arrays are exposed as immutable mappings. Use snapshot(exclude_filesystem=True) when you need shell-only restore bytes, or snapshot(exclude_filesystem=True, exclude_functions=True) when prompt rendering does not need function restore. Transient fields like last_exit_code and traps are captured on the snapshot, but the top-level execute() / execute_sync() clears them before running the new command. BashTool exposes the same shell_state() method.
analyze() reports what a script statically refers to, commands, arguments, redirect targets, function definitions, without running it. Use it to decide whether a model-produced command needs user approval.
Words that are not fully literal report None , never a partial string:
Advisory only. Static analysis cannot see through dynamic dispatch, eval , functions, or aliases. Those set is_opaque , and an allowlist check must consult it, c=rm; $c -rf /data contains no disallowed command name:
Commands inside $(…) , loops, branches, and function bodies are reported too, each
BashTool wraps Bash and adds tool-contract metadata for agent frameworks:
Python Function Calls
Register host functions for code running in embedded Python. Both Bash and BashTool accept external_functions and an async external_handler :
LangChain's create_bash_tool / BashkitTool and deepagents' middleware/backend accept the same options. ainvoke() and BashkitBackend.aexecute() run callbacks on the caller's active asyncio loop, preserving loop-bound clients and request ContextVars. Use these async APIs in FastAPI async endpoints or notebook cells with top-level await .
Synchronous execution works from ordinary threads, FastAPI sync endpoints, and notebook cells with an already-running loop. It drives callbacks on a dedicated private worker loop shared across synchronous calls to that instance. Clients bound to another loop must use the async API. ContextVars are captured for each execution; a shared instance serializes requests. Timeouts and cancellation cancel that execution's pending callback tasks.
If another handler is already waiting on the current loop, synchronous access to that same interpreter fails immediately: blocking the loop would deadlock the handler. Use the async API or move the synchronous operation to asyncio.to_thread() .
Callbacks are trusted host code: enforce service authorization and I/O limits there. They cannot re-enter their own interpreter or live filesystem handles; pass data through arguments/results or use another instance. Function names and handlers survive reset() and in-place restore. Snapshot bytes do not serialize callbacks: supply them again to from_snapshot() / from_snapshot_keyed() .
Runnable notebook: runtime_external_functions.ipynb .
TypeScript Function Calls
BashTool and its LangChain/deepagents adapters also accept separate typescript_external_functions / typescript_external_handler options:
TypeScript dispatch receives (name, args) ; use an object argument for named options. Values cross as None /null, booleans, signed 64-bit integers, finite floats, strings, lists, and string-keyed dictionaries. undefined arguments map to None ; function arguments, unsupported return objects, non-finite numbers, and nesting deeper than 64 levels are rejected. Python and TypeScript handlers can coexist, the VFS, and use the same thread/loop/reset/snapshot rules. Native host handlers are unavailable in the Pyodide build.
ZapCode currently loses console.log() output produced after an external call. Return the final expression as shown above, or write results into the VFS.
Persistent Custom Builtins
Use custom_builtins={...} on Bash or BashTool when you want constructor-time Python callback builtins without giving up persistent shell/VFS state:
Callbacks receive a BuiltinContext object with raw argv tokens, optional pipeline stdin , the current cwd , and visible env . They may return either the builtin stdout string directly or a BuiltinResult(stdout=..., stderr=..., exit_code=...) for explicit shell-shaped failures. Raise an exception for unexpected callback failures. Async callbacks support the same return shapes. BashTool exposes the same custom_builtins constructor kwarg and includes registered command names in help() output for LLM-facing metadata.
When you use await bash.execute(...) or await bash_tool.execute(...) , async callbacks are scheduled back onto the caller's active asyncio loop, so loop-bound primitives like asyncio.Event and framework-owned clients keep working. execute_sync() still supports async callbacks, but it drives them on an internal private loop and should not be called from an async endpoint.
Use ScriptedTool to register Python callbacks as bash-callable tools:
ScriptedTool callbacks receive (params_dict, stdin_or_none) and must return the tool stdout string. Async callbacks are also supported. await tool.execute(...) runs async callbacks on the caller's active asyncio loop; execute_sync() falls back to a private loop because there is no caller loop to reuse.
Unkeyed snapshot() bytes detect accidental corruption only. Use snapshot_keyed(...) , restore_snapshot_keyed(...) , and from_snapshot_keyed(...) whenever snapshot bytes cross trust boundaries such as uploads, shared storage, or network transport.
BashTool exposes the same snapshot, restore, and keyed snapshot APIs. Python callback builtins are host-side config, not serialized shell state, so pass custom_builtins= again when constructing a restored instance if you need them after snapshot restore.
Framework Integrations
Requires Python 3.11+ and pip install 'bashkit[deepagents]' . Full guide: bashkit.sh/docs/deepagents .
Uses the structured Deep Agents 0.7.32+ backend protocol. Shell execution reports native output truncation; file operations preserve exact VFS contents. The constructor timeout_seconds is the execution budget; a per-command timeout from the agent can shorten it but never extend it. Images, PDFs and other binary files are read as base64 (up to 500 KB) so multimodal models can see them, and upload/download failures use the protocol's error codes ( file_not_found , is_directory , permission_denied , invalid_path ).
Large command output is kept in the virtual filesystem: when Deep Agents offloads an execute result, the full combined output (up to 10 MB, beyond the 1 MB in-memory stdout cap) is written to /large_tool_results/ and the model gets a head/tail preview it can follow up with grep or read_file . Shell state ( cd , export , functions) carries over between commands.
Bash / BashTool execute* methods accept the same per-call cap directly: execute_sync("make test", timeout_seconds=10) . execute / execute_sync can also tee combined output to a VFS file: execute_sync("pytest", output_file="/tmp/pytest.log", max_output_file_bytes=10_000_000) .
execute(commands: str) -> ExecResult
execute_sync(commands: str) -> ExecResult
execute_or_throw(commands: str) -> ExecResult
execute_sync_or_throw(commands: str) -> ExecResult
constructor kwarg: custom_builtins={name: callback}
snapshot_keyed(key: bytes) -> bytes
restore_snapshot(data: bytes)
restore_snapshot_keyed(data: bytes, key: bytes)
from_snapshot(data: bytes, **kwargs) -> Bash
from_snapshot_keyed(data: bytes, key: bytes, **kwargs) -> Bash
constructor kwarg: network={"allow": [...], "block_private_ips": True} or network={"allow_all": True} , optionally with credentials=[...] and credential_placeholders=[...]
mount(vfs_path: str, fs: FileSystem)
unmount(vfs_path: str)
Direct VFS helpers: read_file , write_file , append_file , mkdir , remove , exists , stat , read_dir , ls , glob , copy , rename , symlink , chmod , read_link
analyze(script: str) -> ScriptAnalysis , static, pre-execution introspection (see Script Analysis )
All execution, cancellation ( cancel() , clear_cancel() ), reset, snapshot, restore, mount, and direct VFS helpers from Bash
constructor kwarg: custom_builtins={name: callback}
Tool metadata: name , short_description , version
system_prompt() -> str
input_schema() -> str
output_schema() -> str
Returned by analyze(script) .
commands: list[AnalyzedCommand] , every simple command, in source order
redirects: list[AnalyzedRedirect] , path: str | None , mode: "read" | "write" | "append" , is_write: bool
functions: list[str] , function names the script defines
command_names: list[str] , distinct statically known names, first-seen order
has_dynamic_commands / has_interpreter_reentry / has_command_substitution / truncated
is_opaque: bool , the script hides work; allowlist checks must treat this as "ask"
commands_named(name) -> list[AnalyzedCommand] , to_dict() -> dict
AnalyzedCommand : name: str | None , args: list[str | None] , context: str , assignments: list[str] , is_assignment_only: bool
add_tool(name, description, callback, schema=None)
execute(script: str) -> ExecResult
execute_sync(script: str) -> ExecResult
execute_or_throw(script: str) -> ExecResult
execute_sync_or_throw(script: str) -> ExecResult
env(key: str, value: str)
mkdir(path, recursive=False)
write_file(path, content)
read_file(path) -> bytes
append_file(path, content)
remove(path, recursive=False)
read_dir(path) -> list
symlink(target, link)
read_link(path) -> str
FileSystem.real(host_path, writable=False) -> FileSystem
FileSystem.from_capsule(capsule) -> FileSystem
FileSystem.to_capsule() -> object
ExecResult and BashError
Linux: x86_64 , aarch64 (glibc and musl wheels)
macOS: x86_64 , aarch64
Python: 3.9 through 3.14
Bashkit is built on the bashkit Rust core, which implements a sandboxed bash interpreter and virtual filesystem. The Python package exposes that engine through a native extension, so commands run in-process with persistent state and resource limits, without shelling out to the host system.
Bashkit is part of the Everruns ecosystem. See the bashkit monorepo for the Rust core, the JavaScript package ( @everruns/bashkit ), and related tooling.
Release files for bashkit 0.22.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation .
Source distribution (sdist)
Built distributions (wheels)
Total release size: 159.8 MB
Release files / bashkit-0.22.0.tar.gz
Release files / bashkit-0.22.0-cp39-abi3-win_amd64.whl
Release files / bashkit-0.22.0-cp39-abi3-pyemscripten_2025_0_wasm32.whl
Release files / bashkit-0.22.0-cp39-abi3-musllinux_1_1_x86_64.whl
Release files / bashkit-0.22.0-cp39-abi3-musllinux_1_1_aarch64.whl
Release files / bashkit-0.22.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Release files / bashkit-0.22.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Release files / bashkit-0.22.0-cp39-abi3-macosx_11_0_arm64.whl
Release files / bashkit-0.22.0-cp39-abi3-macosx_10_12_x86_64.whl
Security for bashkit 0.22.0
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.
None of the files in this release were uploaded with provenance metadata.
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.
Release history Release notifications | RSS feed
Nov 25, 2026 9 release files No provenance
Nov 19, 2026 9 release files No provenance
Nov 11, 2026 9 release files No provenance
Nov 4, 2026 9 release files No provenance
Oct 30, 2026 9 release files No provenance
Oct 26, 2026 9 release files No provenance
Oct 25, 2026 9 release files No provenance
Oct 15, 2026 9 release files No provenance
Sep 22, 2026 9 release files No provenance
Sep 18, 2026 9 release files No provenance
Sep 11, 2026 9 release files No provenance
Aug 22, 2026 9 release files No provenance
Aug 22, 2026 9 release files No provenance
Aug 7, 2026 9 release files No provenance
Aug 4, 2026 9 release files No provenance
Aug 1, 2026 9 release files No provenance
Jul 27, 2026 9 release files No provenance
Jul 18, 2026 13 release files No provenance
Yanked reason: Partial release
Jul 18, 2026 44 release files No provenance
Jul 18, 2026 44 release files No provenance
Jul 7, 2026 44 release files No provenance
Jun 23, 2026 44 release files No provenance
Jun 16, 2026 44 release files No provenance
Jun 11, 2026 44 release files No provenance
Jun 2, 2026 44 release files No provenance
May 28, 2026 43 release files No provenance
May 27, 2026 43 release files No provenance
May 25, 2026 43 release files No provenance
May 25, 2026 43 release files No provenance
May 17, 2026 43 release files No provenance
May 6, 2026 43 release files No provenance
May 4, 2026 43 release files No provenance
May 4, 2026 43 release files No provenance
May 3, 2026 43 release files No provenance
Apr 30, 2026 43 release files No provenance
Apr 25, 2026 43 release files No provenance
Feb 10, 2026 36 release files No provenance
The full story
This article is one source in a clustered incident — the cluster page carries the summary, timeline and every other outlet covering it.
