Open source CapCut alternative.
TypeScript
fix(app): allow System V IPC in the workspace sandbox so bundled yt-dlp launches
David Le18864c0441ef
diff --git a/apps/Donkey/Sources/DonkeyRuntime/WorkspaceSandbox.swift b/apps/Donkey/Sources/DonkeyRuntime/WorkspaceSandbox.swiftindex 88c65f2e..4a14adb8 100644--- a/apps/Donkey/Sources/DonkeyRuntime/WorkspaceSandbox.swift+++ b/apps/Donkey/Sources/DonkeyRuntime/WorkspaceSandbox.swift@@ -163,7 +163,13 @@ public enum WorkspaceSandbox {"(deny default)","(allow process-fork) (allow process-exec*)","(allow sysctl-read) (allow mach-lookup) (allow signal (target self))",- "(allow ipc-posix-shm*)",+ // IPC: POSIX shared memory plus the System V semaphore/shared-memory pair. A PyInstaller+ // onefile binary (yt-dlp) unpacks and relaunches itself using a System V semaphore for the+ // parent/child handshake; under (deny default) `semctl` returns "Operation not permitted" and+ // the bootloader dies before the tool runs at all — which reads to the agent as a broken tool+ // and sends it hunting for a pip/python install path. IPC is not a filesystem escape, so+ // allowing it keeps the jail's filesystem-only contract intact while letting bundled tools run.+ "(allow ipc-posix-shm*) (allow ipc-sysv-sem) (allow ipc-sysv-shm)","(allow file-read-metadata)"]if policy.allowNetwork { lines.append("(allow network*)") }diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/WorkspaceSandboxTests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/WorkspaceSandboxTests.swiftindex 851d1ea6..f5d78451 100644--- a/apps/Donkey/Tests/DonkeyRuntimeTests/WorkspaceSandboxTests.swift+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/WorkspaceSandboxTests.swift@@ -33,6 +33,18 @@ struct WorkspaceSandboxTests {#expect(sbpl.contains("(allow file-read* (subpath \"/\"))"))}+ @Test+ func profileAllowsSystemVIPCForSelfExtractingTools() {+ // A PyInstaller onefile binary (yt-dlp) relaunches itself through a System V semaphore; without+ // this rule its bootloader dies with `semctl: Operation not permitted` under (deny default), which+ // the agent misreads as a broken tool. Lock the allowance in so a profile edit can't silently drop+ // it and resurrect the pip/python consent loop.+ let policy = SandboxPolicy(writableRoots: ["/private/tmp"], allowAllReads: true)+ let sbpl = WorkspaceSandbox.profile(for: policy, programPath: "/usr/bin:/bin", bundledToolsDir: nil)+ #expect(sbpl.contains("(allow ipc-sysv-sem)"))+ #expect(sbpl.contains("(allow ipc-sysv-shm)"))+ }+@Testfunc networkIsOmittedWhenDisallowed() {let policy = SandboxPolicy(writableRoots: ["/private/tmp"], readableRoots: [], allowNetwork: false)@@ -116,6 +128,59 @@ struct WorkspaceSandboxTests {#expect(FileManager.default.fileExists(atPath: escape) == false)}+ @Test+ func systemVSemaphoreSucceedsInsideTheJail() throws {+ // The real failure that sent the agent into the pip/python consent loop: a System V semaphore op+ // (semget/semctl) denied by the seatbelt. Prove the kernel now permits it under the wrap by+ // compiling and running a tiny program that does exactly what yt-dlp's bootloader does. Skipped+ // cleanly if no C compiler is available.+ try requireSandboxExec()+ let cc = "/usr/bin/cc"+ try #require(FileManager.default.isExecutableFile(atPath: cc))++ let base = try makeBase()+ defer { try? FileManager.default.removeItem(atPath: base) }+ let source = base + "/sem.c"+ let binary = base + "/sem"+ try """+ #include <sys/sem.h>+ int main(void) {+ int id = semget(IPC_PRIVATE, 1, IPC_CREAT | 0600); // what fails under a too-tight jail+ if (id < 0) return 1;+ semctl(id, 0, IPC_RMID); // the call that emitted "Operation not permitted"+ return 0;+ }+ """.write(toFile: source, atomically: true, encoding: .utf8)++ // Compile unsandboxed; only the run needs to be confined.+ let compile = Process()+ compile.executableURL = URL(fileURLWithPath: cc)+ compile.arguments = [source, "-o", binary]+ compile.standardOutput = FileHandle.nullDevice+ compile.standardError = FileHandle.nullDevice+ try compile.run()+ compile.waitUntilExit()+ try #require(compile.terminationStatus == 0)++ // Run it inside the jail — the kernel must allow the SysV semaphore calls.+ let policy = SandboxPolicy(writableRoots: [base], allowNetwork: false)+ let (exe, args) = WorkspaceSandbox.wrap(+ executable: URL(fileURLWithPath: binary),+ arguments: [],+ policy: policy,+ environment: ["PATH": "/usr/bin:/bin"],+ bundledToolsDir: nil+ )+ let run = Process()+ run.executableURL = exe+ run.arguments = args+ run.standardOutput = FileHandle.nullDevice+ run.standardError = FileHandle.nullDevice+ try run.run()+ run.waitUntilExit()+ #expect(run.terminationStatus == 0)+ }+// MARK: - Helpersprivate func requireSandboxExec() throws {