Skip to main content

Crate rust_bash

Crate rust_bash 

Source
Expand description

A sandboxed bash interpreter with a virtual filesystem.

rust-bash executes bash scripts safely in-process — no containers, no VMs, no host access. All file operations happen on a pluggable virtual filesystem (in-memory by default), and configurable execution limits prevent runaway scripts.

§Quick start

use rust_bash::RustBashBuilder;
use std::collections::HashMap;

let mut shell = RustBashBuilder::new()
    .files(HashMap::from([
        ("/hello.txt".into(), b"hello world".to_vec()),
    ]))
    .build()
    .unwrap();

let result = shell.exec("cat /hello.txt").unwrap();
assert_eq!(result.stdout, "hello world");
assert_eq!(result.exit_code, 0);

§Features

  • 80+ built-in commands — echo, cat, grep, awk, sed, jq, find, sort, diff, curl, and more
  • Full bash syntax — pipelines, redirections, variables, control flow, functions, command substitution, globs, brace expansion, arithmetic, here-documents, case statements
  • Execution limits — 10 configurable bounds (time, commands, loops, output size, etc.)
  • Network policy — sandboxed curl with URL allow-lists and method restrictions
  • Multiple filesystem backendsInMemoryFs, OverlayFs, ReadWriteFs, MountableFs
  • Custom commands — implement the VirtualCommand trait to add your own
  • C FFI and WASM — embed in any language via shared library or WebAssembly

Re-exports§

pub use api::RustBash;
pub use api::RustBashBuilder;
pub use commands::CommandContext;
pub use commands::CommandResult;
pub use commands::ExecCallback;
pub use commands::VirtualCommand;
pub use error::RustBashError;
pub use error::VfsError;
pub use interpreter::ExecResult;
pub use interpreter::ExecutionCounters;
pub use interpreter::ExecutionLimits;
pub use interpreter::InterpreterState;
pub use interpreter::ShellOpts;
pub use interpreter::Variable;
pub use interpreter::VariableAttrs;
pub use interpreter::VariableValue;
pub use interpreter::builtin_names;
pub use network::NetworkPolicy;
pub use vfs::DirEntry;
pub use vfs::InMemoryFs;
pub use vfs::Metadata;
pub use vfs::MountableFs;
pub use vfs::NodeType;
pub use vfs::VirtualFs;
pub use vfs::OverlayFs;
pub use vfs::ReadWriteFs;

Modules§

api
Public API: RustBash shell instance and builder.
commands
Command trait and built-in command implementations.
error
interpreter
Interpreter engine: parsing, AST walking, and execution state.
mcp
MCP (Model Context Protocol) server over stdio.
network
platform
Platform abstraction for types that differ between native and WASM.
vfs