90 releases (31 stable)

4.0.2 Feb 15, 2026
4.0.0 Dec 11, 2025
3.4.5 Oct 24, 2025
3.4.4 Apr 21, 2025
0.0.0 Jun 25, 2020

#13 in Network programming

Download history 136723/week @ 2026-01-23 136458/week @ 2026-01-30 130782/week @ 2026-02-06 155751/week @ 2026-02-13 171894/week @ 2026-02-20 208520/week @ 2026-02-27 228206/week @ 2026-03-06 200868/week @ 2026-03-13 195834/week @ 2026-03-20 234680/week @ 2026-03-27 212586/week @ 2026-04-03 232882/week @ 2026-04-10 239194/week @ 2026-04-17 264515/week @ 2026-04-24 264434/week @ 2026-05-01 299324/week @ 2026-05-08

1,109,884 downloads per month
Used in 752 crates (64 directly)

Apache-2.0…

570KB
12K SLoC

cap-std

Capability-based version of the Rust standard library

Github Actions CI Status crates.io page docs.rs docs

This crate provides a capability-based version of std, providing sandboxed filesystem, networking, and clock APIs. See the toplevel README.md for more information about sandboxing using capability-based security.

The filesystem module cap_std::fs, the networking module cap_std::net, and the time module cap_std::time currently support Linux, macOS, FreeBSD, and Windows. WASI support is in development, though not yet usable.

Example usage of Dir for filesystem access:

use std::io;
use cap_std::fs::Dir;

/// Open files relative to `dir`.
fn dir_example(dir: &Dir) -> io::Result<()> {
    // This works (assuming symlinks don't lead outside of `dir`).
    let file = dir.open("the/thing.txt")?;

    // This fails, since `..` leads outside of `dir`.
    let hidden = dir.open("../hidden.txt")?;

    // This fails, as creating symlinks to absolute paths is not permitted.
    dir.symlink("/hidden.txt", "misdirection.txt")?;

    // However, even if the symlink had succeeded, or, if there is a
    // pre-existing symlink to an absolute directory, following a
    // symlink which would lead outside the sandbox also fails.
    let secret = dir.open("misdirection.txt")?;

    Ok(())
}

Example usage of Pool for network access:

use std::io;
use cap_std::net::Pool;

/// Open network addresses within `pool`.
fn pool_example(pool: &Pool) -> io::Result<()> {
    // Connect to an address. This succeeds only if the given address and
    // port are present in `pool`.
    let stream = pool.connect_tcp_stream("localhost:3333")?;

    Ok(())
}

Dependencies

~2–13MB
~135K SLoC