TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 229 subscribers
Post #24296 12
how to sandbox a c++ child process on MacOSX?

So here is what I want to do:

I have a parent process that is trusted. I want this parent process to run a child process, which is untrusted.

The child can be an arbitrarily sourced script, or just written pooly. I want it run safely, without worrying (too much) about the child "doing bad things".

The child will communicate to it's parent via message-passing, probably via shared-memory.

These child will be a script, in a language that I have made, and run in a VM. However, this VM has access to low-level unix functions, like exec/kill/open/read/write/remove/etc. This is fine for trusted scripts.

But for untrusted scripts, it is not acceptable.

Instead, I want to block access to almost all syscalls. I've seen proposals like disable(): https://www.reddit.com/r/osdev/comments/1mpphmo/adding\_a\_disable\_syscall/ But of course... this does not exist yet.

OpenBSD has a "pledge()" call. But I need this on OSX.

I've heard of `ptrace()`being used to acheive this. I don't know how to do this. Does this work well on MacOSX?

Obviously... the idea is to acheive this workflow:

1. Parent sets up shared-memory for communication
2. Parent calls fork
3. Forked child drops most of the permissions or abilities
4. Forked child calls exec()
5. Exec'd child then has to drop the permission to call exec!
6. Exec'd child finally does the required work

Something like that. That or something simpler that acheives the same goal.

I don't need this immediately, but sometime before 3 months I will want this. But I can start today if I get good info today.

https://redd.it/1p249qy
@r_cpp
Reddit From the osdev community on Reddit: Adding a disable() syscall Explore this post and more from the osdev community
More from @r_cpp
  1. Oct 12, 2026ACCU Overload Journal 195 - October 2026 https://accu.org/journals/overload/overload195 ht…
  2. Oct 12, 2026C++ Contracts C++ contracts are a good thing, why are people saying it's a bad thing? Anyb…
  3. Oct 11, 2026wxWidgets 3.2.12 and 3.3.4 Released https://wxwidgets.org/news/2026/10/wxwidgets-3.2.12-an…
  4. Oct 11, 2026VKRT NES Remaster — an open-source C++20 NES emulator with an observation-driven remasteri…
  5. Oct 11, 2026Right way to test async code https://redd.it/1x2wqgz @r_cpp
  6. Oct 10, 2026Yantra: an LALR(1) parser generator for C++23 Yantra: an LALR(1) parser generator for C++2…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →