{"record":{"id":"038a630660f86625","repo":"elastic/elasticsearch","slug":"sandbox-init","errorCode":null,"errorMessage":"sandbox_init(): {}","messagePattern":"sandbox_init\\(\\): (.+?)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"warning","filePath":"libs/native/src/main/java/org/elasticsearch/nativeaccess/MacNativeAccess.java","lineNumber":139,"sourceCode":"\n        // write rules to a temporary file, which will be passed to sandbox_init()\n        Path rules;\n        try {\n            rules = createTempRulesFile();\n            Files.write(rules, Collections.singleton(SANDBOX_RULES));\n        } catch (IOException e) {\n            throw new UncheckedIOException(e);\n        }\n\n        try (Arena arena = Arena.ofConfined()) {\n            MemorySegment errorBuf = arena.allocate(ValueLayout.ADDRESS);\n            int ret = macLibc.sandbox_init(rules.toAbsolutePath().toString(), SANDBOX_NAMED, errorBuf);\n            // if sandbox_init() fails, add the message from the OS (e.g. syntax error) and free the buffer\n            if (ret != 0) {\n                MemorySegment errorPtr = errorBuf.get(ValueLayout.ADDRESS, 0);\n                String message = MemorySegmentAdapter.getString(errorPtr.reinterpret(Long.MAX_VALUE), 0);\n                macLibc.sandbox_free_error(errorPtr);\n                throw new UnsupportedOperationException(\"sandbox_init(): \" + message);\n            }\n            logger.debug(\"OS X seatbelt initialization successful\");\n        } finally {\n            IOUtils.deleteFilesIgnoringExceptions(rules);\n        }\n    }\n\n    private void initBsdSandbox() {\n        RLimit limit = libc.newRLimit();\n        limit.rlim_cur(0);\n        limit.rlim_max(0);\n        // not a standard limit, means something different on linux, etc!\n        final int RLIMIT_NPROC = 7;\n        if (libc.setrlimit(RLIMIT_NPROC, limit) != 0) {\n            throw new UnsupportedOperationException(\"RLIMIT_NPROC unavailable: \" + libc.strerror(libc.errno()));\n        }\n\n        logger.debug(\"BSD RLIMIT_NPROC initialization successful\");","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/native/src/main/java/org/elasticsearch/nativeaccess/MacNativeAccess.java#L121-L157","documentation":"Thrown during macOS seatbelt sandbox setup in tryInstallExecSandbox() → initMacSandbox(). The code writes sandbox rules to a temp file and calls macLibc.sandbox_init(rulesPath, SANDBOX_NAMED, errorBuf). If sandbox_init returns non-zero, the OS-provided error message (e.g. syntax error in rules, unsupported operation) is extracted from errorBuf, freed via sandbox_free_error, and appended to this exception. This is the macOS equivalent of the Linux seccomp filter installation.","triggerScenarios":"Calling tryInstallExecSandbox() on macOS where macLibc.sandbox_init(rules.toAbsolutePath().toString(), SANDBOX_NAMED, errorBuf) returns non-zero. The OS error message from the errorBuf MemorySegment is appended to the exception string.","commonSituations":"macOS version incompatibility where the sandbox policy language or API has changed; SIP (System Integrity Protection) restrictions interfering with sandbox_init; corrupted or truncated SANDBOX_RULES constant string; running under an existing sandbox that conflicts; macOS beta releases with API changes.","solutions":["Read the OS-provided error message appended after 'sandbox_init(): ' — it typically describes the specific syntax or policy error.","Verify the macOS version is supported by this ES build.","Check if SIP or an existing sandbox (e.g. running inside another sandboxed app) conflicts with seatbelt initialization.","If running in a CI/test environment on macOS, try disabling the sandbox requirement.","The sandbox_check at line 112 skips initialization if already sandboxed — verify that check is not being bypassed."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    nativeAccess.tryInstallExecSandbox();\n} catch (UnsupportedOperationException e) {\n    // macOS sandbox_init() failed; the OS error message is appended.\n    logger.warn(\"macOS seatbelt sandbox unavailable: {}\", e.getMessage());\n}","preventionTips":["Run ES on supported macOS versions only — check the compatibility matrix.","Verify SIP is not interfering with sandbox_init in your deployment environment.","Check that the process is not already inside a conflicting sandbox (sandbox_check at line 112 should catch this).","Read the OS-provided error message for specific syntax/policy errors."],"tags":["macos","seatbelt","security","native","sandbox","bootstrap"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}