macOS Default Sandbox Debug

In this page you can find how to create an app to launch arbitrary commands from inside the default macOS sandbox:

  1. Compile the application:

main.m
#include <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        while (true) {
            char input[512];

            printf("Enter command to run (or 'exit' to quit): ");
            if (fgets(input, sizeof(input), stdin) == NULL) {
                break;
            }

            // Remove newline character
            size_t len = strlen(input);
            if (len > 0 && input[len - 1] == '\n') {
                input[len - 1] = '\0';
            }

            if (strcmp(input, "exit") == 0) {
                break;
            }

            system(input);
        }
    }
    return 0;
}

Compile it running: clang -framework Foundation -o SandboxedShellApp main.m

  1. Build the .app bundle

  1. Define the entitlements

  1. Sign the app (you need to create a certificate in the keychain)

Last updated