BashKit
Sandboxed bash interpreter for multi-tenant environments. Written in Rust.
Features
- POSIX compliant - Substantial IEEE 1003.1-2024 Shell Command Language compliance
- Sandboxed execution - No real filesystem access by default
- Virtual filesystem - InMemoryFs, OverlayFs, MountableFs
- Resource limits - Command count, loop iterations, function depth
- Network allowlist - Control HTTP access per-domain
- Async-first - Built on tokio
Quick Start
use Bash;
async
Built-in Commands (60+)
| Category | Commands |
|---|---|
| Core | echo, printf, cat, read |
| Navigation | cd, pwd, ls, find |
| Flow control | true, false, exit, return, break, continue, test, [ |
| Variables | export, set, unset, local, shift, source |
| Text processing | grep, sed, awk, jq, head, tail, sort, uniq, cut, tr, wc |
| File operations | mkdir, rm, cp, mv, touch, chmod, rmdir |
| File inspection | file, stat, less |
| Archives | tar, gzip, gunzip |
| Utilities | sleep, date, basename, dirname, timeout, wait |
| Pipeline | xargs, tee |
| System info | whoami, hostname, uname, id, env, printenv |
| Network | curl, wget (stub, requires allowlist) |
Shell Features
- Variables and parameter expansion (
$VAR,${VAR:-default},${#VAR}) - Command substitution (
$(cmd)) - Arithmetic expansion (
$((1 + 2))) - Pipelines and redirections (
|,>,>>,<,<<<) - Control flow (
if/elif/else,for,while,case) - Functions (POSIX and bash-style)
- Arrays (
arr=(a b c),${arr[@]},${#arr[@]}) - Glob expansion (
*,?) - Here documents (
<<EOF)
Configuration
use ;
use Arc;
let limits = new
.max_commands
.max_loop_iterations
.max_function_depth;
let mut bash = builder
.fs
.env
.cwd
.limits
.build;
Sandbox Identity
Configure the sandbox username and hostname for whoami, hostname, id, and uname:
let mut bash = builder
.username // Sets whoami, id, and $USER env var
.hostname // Sets hostname, uname -n
.build;
// whoami → "deploy"
// hostname → "my-server"
// id → "uid=1000(deploy) gid=1000(deploy)..."
// echo $USER → "deploy"
Virtual Filesystem
use ;
use Arc;
// Layer filesystems
let base = new;
let overlay = new;
// Mount points
let mut mountable = new;
mountable.mount;
CLI Usage
# Run a script
# Interactive REPL
Development
Benchmarks
BashKit includes a benchmark tool to compare performance against bash and just-bash.
Key findings:
- ~2000x faster startup - No subprocess overhead (0.004ms vs 9ms)
- ~200-1000x faster for tools - grep/sed/awk run in-process
- ~550x faster recursive functions - Fibonacci(10): 1ms vs 586ms
See crates/bashkit-bench/README.md for methodology and assumptions.
Acknowledgments
This project was inspired by just-bash from Vercel Labs. Huge kudos to the Vercel team for pioneering the idea of a sandboxed bash interpreter for AI-powered environments. Their work laid the conceptual foundation that made BashKit possible.
License
MIT