jailer

Crate which helps in creation of sandbox environment

Latest version: 0.4.1 registry icon
Maintenance score
27
Safety score
100
Popularity score
70
Check your open source dependency risks. Get immediate insight about security, stability and licensing risks.
Security
  Vulnerabilities
Version Suggest Low Medium High Critical
0.4.1 0 0 0 0 0
0.4.0 0 0 0 0 0
0.3.0 0 0 0 0 0
0.2.0 0 0 0 0 0
0.1.1 0 0 0 0 0
0.1.0 0 0 0 0 0

Stability
Latest release:

0.4.1 - This version may not be safe as it has not been updated for a long time. Find out if your coding project uses this component and get notified of any reported security vulnerabilities with Meterian-X Open Source Security Platform

Licensing

Maintain your licence declarations and avoid unwanted licences to protect your IP the way you intended.

MIT   -   MIT License

Not a wildcard

Not proprietary

OSI Compliant



Jailer

Project status & info:

License Crates Version Docs
License: MIT Crate Docs

Crate to create a sandbox environment for testing and other use cases. It provides an isolated temporary directory that automatically cleans up upon closure or when the object goes out of scope.

Add as dependencies

Edit Cargo.toml file to add jailer as dependencies

[dependencies]
jailer = "0.4.1"

Usage

Jailer allows you to create a temporary directory where all operations occur. Once the jailer instance is dropped or closed, the directory and its contents are automatically deleted.

let jailer = jailer::Jailer::new().unwrap();
// use rust code as required
// Data is deleted when jailer is dropped or when it is closed
jailer.close().unwrap();

Using EnvJailer for Environment Variable Isolation

EnvJailer extends Jailer by also managing environment variables. It ensures that environment changes within the jail do not persist beyond its lifetime.

use jailer::EnvJailer;

let mut env_jailer = EnvJailer::new().unwrap();
unsafe {
    std::env::set_var("KEY", "VALUE");
    std::env::set_var("KEY2", "VALUE2");
}
env_jailer.set_preserved_env("KEY");
assert_eq!(std::env::var("KEY"), Ok("VALUE".to_string()));
unsafe {
    std::env::set_var("KEY", "VALUE2");
}
assert_eq!(std::env::var("KEY"), Ok("VALUE2".to_string()));
unsafe {
    env_jailer.close().unwrap();
}
assert_eq!(std::env::var("KEY"), Ok("VALUE2".to_string()));
assert!(std::env::var("KEY2").is_err());