#virtualization #sandbox #namespaces #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

#27 in #namespaces

Download history 6/week @ 2024-01-26 16/week @ 2024-02-02 7/week @ 2024-02-16 7/week @ 2024-02-23 23/week @ 2024-03-01 124/week @ 2024-03-08 2/week @ 2024-03-15 5/week @ 2024-03-29

137 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–13MB
~149K SLoC