pub struct Bash { /* private fields */ }Expand description
Main entry point for BashKit.
Provides a sandboxed bash interpreter with an in-memory virtual filesystem.
Implementations§
Source§impl Bash
impl Bash
Sourcepub fn builder() -> BashBuilder
pub fn builder() -> BashBuilder
Create a new BashBuilder for customized configuration.
Sourcepub async fn exec(&mut self, script: &str) -> Result<ExecResult>
pub async fn exec(&mut self, script: &str) -> Result<ExecResult>
Execute a bash script and return the result.
This method first validates that the script does not exceed the maximum input size, then parses the script with a timeout, AST depth limit, and fuel limit, then executes the resulting AST.
Sourcepub fn fs(&self) -> Arc<dyn FileSystem>
pub fn fs(&self) -> Arc<dyn FileSystem>
Get a clone of the underlying filesystem.
Provides direct access to the virtual filesystem for:
- Pre-populating files before script execution
- Reading binary file outputs after execution
- Injecting test data or configuration
§Example
use bashkit::Bash;
use std::path::Path;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let mut bash = Bash::new();
let fs = bash.fs();
// Pre-populate config file
fs.mkdir(Path::new("/config"), false).await?;
fs.write_file(Path::new("/config/app.txt"), b"debug=true\n").await?;
// Bash script can read pre-populated files
let result = bash.exec("cat /config/app.txt").await?;
assert_eq!(result.stdout, "debug=true\n");
// Bash creates output, read it directly
bash.exec("echo 'done' > /output.txt").await?;
let output = fs.read_file(Path::new("/output.txt")).await?;
assert_eq!(output, b"done\n");
Ok(())
}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Bash
impl !RefUnwindSafe for Bash
impl Send for Bash
impl Sync for Bash
impl Unpin for Bash
impl !UnwindSafe for Bash
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more