# Restricted - limit possible system operations and filesystem view of your program

**URL:** <https://ziggit.dev/t/restricted-limit-possible-system-operations-and-filesystem-view-of-your-program/14234>\
**Category:** Showcase\
**Created:** [February 7, 2026, 7:15pm UTC](https://ziggit.dev/t/restricted-limit-possible-system-operations-and-filesystem-view-of-your-program/14234 "2026-02-07T19:15:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![removewingman](https://ziggit.dev/letter_avatar_proxy/v4/letter/r/57b2e6/32.png) [@removewingman](https://ziggit.dev/u/removewingman)\
**Post date:** [February 7, 2026, 7:15pm UTC](https://ziggit.dev/t/restricted-limit-possible-system-operations-and-filesystem-view-of-your-program/14234/1 "2026-02-07T19:15:05Z")

</div>

Hello,

I would like to announce a new package [restricted](https://codeberg.org/removewingman/restricted-zig).

This library lets you limit which system operations and which parts of the filesystem your program can access. Call it as early as possible in your program so that the rest of the code runs with reduced privileges. Currently, actual enforced restrictions are implemented for these operating systems:

- OpenBSD

Even on other operating systems, you can still use [restricted](https://removewingman.codeberg.page/restricted-zig/) to document which privileges your program needs. Users can then test if your program respects these promises with tools such as [pledge on Linux](https://justine.lol/pledge/). Enjoy 🙂

- [api](https://removewingman.codeberg.page/restricted-zig/)
- [documented usage and examples](https://codeberg.org/removewingman/restricted-zig#usage-and-examples)
- [License AGPL](https://en.wikipedia.org/wiki/GNU_Affero_General_Public_License)

PS: Thanks for the awesome language and especially the simple tooling  
PS 2: Thanks for trying to get rid off llvm in the long run, it is so annoying

---

<div class="post-metadata">

**Author:** ![removewingman](https://ziggit.dev/letter_avatar_proxy/v4/letter/r/57b2e6/32.png) [@removewingman](https://ziggit.dev/u/removewingman)\
**Post date:** [August 12, 2026, 7:04pm UTC](https://ziggit.dev/t/restricted-limit-possible-system-operations-and-filesystem-view-of-your-program/14234/2 "2026-08-12T19:04:02Z")

</div>

## 2.0.0 - 2026-08-12

- tested on:
  - x86\_64 openbsd (16/16 Tests passed)
  - x86\_64 alpine linux (0/0 Tests passed)

### Changed

- Update to latest Zig 0.17.0-dev version

### Added

- API: exec promises
- OpenBSD: exec promises tests

### Removed

- SystemOperation.TmpPath (deprecated see: `pledge (2)`)

Example for reading file:

```zig
const std = @import("std");
const restricted = @import("restricted");

const Error = error{WrongContent};

const file_name = "read_me.txt";

pub fn main(init: std.process.Init) !void {
    try restricted.restrict(
        &[_]restricted.SystemOperation{
            .StdinStdoutStderrAndBasicFunctionality,
            .ReadFromFilesystem,
        },
        &[_]restricted.SystemOperation{},
        &[_]restricted.PathAccess{.{ .path = file_name, .permissions = &[_]restricted.PathPermission{
            .Read,
        } }},
        init.gpa,
    );
    var stdin_buffer: [1024]u8 = undefined;
    const file_content = try std.Io.Dir.cwd().readFile(init.io, file_name, &stdin_buffer);
    const expected_content = "simplicity\n";
    if (!std.mem.eql(u8, expected_content, file_content)) {
        std.log.err("did read wrong content: {s}", .{file_content[0..]});
        return Error.WrongContent;
    }
}

```

[zigpkg.dev](https://zigpkg.dev/packages/removewingman/restricted-zig)

---

<div class="post-metadata">

**Author:** ![removewingman](https://ziggit.dev/letter_avatar_proxy/v4/letter/r/57b2e6/32.png) [@removewingman](https://ziggit.dev/u/removewingman)\
**Post date:** [December 3, 2026, 8:40pm UTC](https://ziggit.dev/t/restricted-limit-possible-system-operations-and-filesystem-view-of-your-program/14234/3 "2026-12-03T20:40:35Z")

</div>

# [0.1.1] - 2026-12-03

- tested on:
  - x86\_64 openbsd (14/14 Tests passed)
  - x86\_64 alpine linux (0/0 Tests passed)

## Added

- add actual error reporting for: RestrictedError, UnveilError, PledgeError
- some doc, structual and error reporting improvements

## Changed

- call unveil before pledge
- update to latest zig 0.18.0-dev version
- make git repo `sha256` and therefore reset history

Small example:

```zig
const std = @import("std");
const restricted = @import("restricted");

pub fn main(init: std.process.Init) !void {
    try restricted.restrict(
        &.{
            .StdinStdoutStderrAndBasicFunctionality,
            .ReadFromFilesystem,
        },
        &.{},
        &.{
            .{
                .path = "read_me.txt",
                .permissions = &.{ .Read },
            },
        },
        init.gpa,
    );

    // your program
    var stdin_buffer: [1024]u8 = undefined;
    const file_content = try std.Io.Dir.cwd().readFile(init.io, "read_me.txt", &stdin_buffer);
    const expected_content = "simplicity\n";
    if (!std.mem.eql(u8, expected_content, file_content)) {
        std.log.err("did read wrong content: {s}", .{file_content[0..]});
        return error.WrongContent;
    }
}

```
