# Run step with elevated priviledges

**URL:** <https://ziggit.dev/t/run-step-with-elevated-priviledges/16668>\
**Category:** Help\
**Tags:** build-system\
**Created:** [July 12, 2026, 6:31am UTC](https://ziggit.dev/t/run-step-with-elevated-priviledges/16668 "2026-07-12T06:31:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeffective](https://ziggit.dev/user_avatar/ziggit.dev/jeffective/32/3116_2.png) [@jeffective](https://ziggit.dev/u/jeffective)\
**Post date:** [July 12, 2026, 6:31am UTC](https://ziggit.dev/t/run-step-with-elevated-priviledges/16668/1 "2026-07-12T06:31:33Z")

</div>

I have am making an application that requires CAP\_NET\_RAW. I would like to include a convenience run step so I can change my current workflow:

```sh
zig build
sudo zig-out/bin/gatorcat --log-level err dc --ifname enx00e04c68006a --recv-timeout-us 50000 --config-file eni.zon

```

to this:

```sh
zig build run --log-level err dc --ifname enx00e04c68006a --recv-timeout-us 50000 --config-file eni.zon

```

Is this possible? I think this is not generally possible since I would have to run the zig compiler with sudo… but maybe somebody knows something about capabilities that I don’t know.

---

<div class="post-metadata">

**Author:** ![rpkak](https://ziggit.dev/letter_avatar_proxy/v4/letter/r/a4c791/32.png) [@rpkak](https://ziggit.dev/u/rpkak)\
**Post date:** [July 12, 2026, 7:30am UTC](https://ziggit.dev/t/run-step-with-elevated-priviledges/16668/2 "2026-07-12T07:30:31Z")

</div>

You can run the run step with `sudo` without having to run the compiler with `sudo`:

Replace something like `const run_cmd = b.addRunArtifact(exe);` with:

```zig
const opt_executor = b.option([]const u8, "executor", "executor");

const run_cmd = if (opt_executor) |executor| blk: {
    const executor_run = b.addSystemCommand(&.{executor});
    executor_run.addArtifactArg2(exe, .{});
    break :blk executor_run;
} else b.addRunArtifact(exe);

```

Then you can use the `-Dexecutor=sudo` option to execute your executable, but not the compiler with `sudo`.

You can also just hardcode `sudo` into an `addSystemCommand`.

---

<div class="post-metadata">

**Author:** ![pzittlau](https://ziggit.dev/letter_avatar_proxy/v4/letter/p/ecae2f/32.png) [@pzittlau](https://ziggit.dev/u/pzittlau)\
**Post date:** [July 12, 2026, 9:51am UTC](https://ziggit.dev/t/run-step-with-elevated-priviledges/16668/3 "2026-07-12T09:51:02Z")

</div>

You could also have a separate `setcap` step that sets the required capabilities on the produced binary. This makes it then also easy to use it in other ways like with a debugger.
