#virtualization #sandbox #linux

sbox

Tiny Linux containers implementation

9 releases

0.1.8 Feb 7, 2024
0.1.7 Feb 6, 2024
0.1.1 Jan 31, 2024

#38 in #sandbox

Download history 16/week @ 2024-01-31 6/week @ 2024-02-07 2/week @ 2024-02-14 8/week @ 2024-02-21 21/week @ 2024-02-28 126/week @ 2024-03-06 6/week @ 2024-03-13 2/week @ 2024-03-27 3/week @ 2024-04-03

78 downloads per month

MIT/Apache

37KB
912 lines

sbox

crates.io codecov

Tiny Linux containers implementation.

Usage

fn main() {
    // Create user namespace mapper for current user with subuids and subgids.
    let user_mapper = NewIdMap::new_root_subid(getuid(), getgid()).unwrap();
    // Create container manager.
    let manager = Manager::new("/tmp/sbox", "/sys/fs/cgroup/sbox", user_mapper).unwrap();
    // Create container.
    let mut container = manager
        .create_container(
            "example".into(),
            ContainerConfig {
                layers: vec!["/tmp/sbox-rootfs".into()],
                ..Default::default()
            },
        )
        .unwrap();
    // Start container.
    let process = container
        .start(ProcessConfig {
            command: vec!["/bin/sh".into(), "-c".into(), "echo 'Hello, World!'".into()],
            ..Default::default()
        })
        .unwrap();
    // Wait for init process exit.
    process.wait(None).unwrap();
    // Remove all container resources.
    container.destroy().unwrap();
}

License

sbox is distributed under the terms of both the MIT license and the Apache 2.0 License.

Dependencies

~3–12MB
~147K SLoC