Hey, thanks for the report. The analysis and the repro tests really help because they cut out all the noise.
You’re right about the root cause. The AppArmor profile for the Agent CLI cursor_sandbox_agent_cli, which matches ~/.local/share/cursor-agent/versions/*/cursorsandbox, is shipped with userns commented out, the line #userns, for compatibility with AppArmor < 4.0. On AppArmor 4.0+ with apparmor_restrict_unprivileged_userns=1, a confined process must have an explicit userns rule to call unshare(CLONE_NEWUSER). Without it, the LSM hook userns_create returns EPERM. This is a known issue, same class as AppArmor cursor-sandbox profile incomplete on Linux — sandbox does not work correctly (missing network, signal, userns) and Linux: terminal sandbox preflight fails — `uid_map` EPERM after mitigations (earlier: loopback error).
Why strace -f makes the error go away. On newer Ubuntu kernels, ptraced processes go through a relaxed path in userns_create, so the AppArmor restriction is effectively bypassed. This isn’t a strace bug, and it’s not a timing thing. It’s just a side effect of the interaction between ptrace and the AppArmor hook.
For a workaround in your environment, shared HPC with no sudo. If you can’t edit /etc/apparmor.d/... and you can’t set sysctl kernel.apparmor_restrict_unprivileged_userns=0, there’s basically no user level workaround besides the strace wrapper you’re already using. If you can, ask the cluster admin to add userns, plus network, signal, dac_override if needed to the cursor_sandbox_agent_cli profile. A ready to use template with local includes and dpkg-divert is in post #10 of this thread AppArmor cursor-sandbox profile incomplete on Linux — sandbox does not work correctly (missing network, signal, userns) - #10 by gcespedes. You can hand it to the admin as-is, it includes the Agent CLI profile.
On our side, I’ve also reported this internally, specifically the Agent CLI userns gap since the existing AppArmor profile tickets don’t directly cover this case. I can’t share an ETA yet, but we’ll post an update here when we have one.