Unable to run Java in sandbox in macOS

Where does the bug appear (feature/product)?

Cursor IDE

Describe the Bug

Java doesn’t seem to work inside the sandbox. Something about how /usr/bin/java enumerates the available JDKs is being blocked.

In the sandbox, both java -version and /usr/libexec/java_home -V give:

The operation couldn't be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.

Outside the sandbox, /usr/lib/java_home -V lists the JVMs:

Matching Java Virtual Machines (3):
    25.0.1 (arm64) "Eclipse Adoptium" - "OpenJDK 25.0.1" /Library/Java/JavaVirtualMachines/temurin-25.jdk/Contents/Home
    21.0.5 (arm64) "Eclipse Adoptium" - "OpenJDK 21.0.5" /Users/me/Library/Java/JavaVirtualMachines/temurin-21.0.5/Contents/Home
    17.0.5 (arm64) "Eclipse Adoptium" - "OpenJDK 17.0.5" /Users/me/Library/Java/JavaVirtualMachines/temurin-17.0.5/Contents/Home
/Library/Java/JavaVirtualMachines/temurin-25.jdk/Contents/Home

If I actually symlink the bin/java binary from one of those into my workspace and tell the agent to run it in the sandbox, it works.

./runjava25

openjdk version "25.0.1" 2025-10-21 LTS
OpenJDK Runtime Environment Temurin-25.0.1+8 (build 25.0.1+8-LTS)
OpenJDK 64-Bit Server VM Temurin-25.0.1+8 (build 25.0.1+8-LTS, mixed mode, sharing)

Steps to Reproduce

Ask the agent to run java -version inside the sandbox

Operating System

MacOS

Version Information

Version: 2.5.17 (Universal)
VSCode Version: 1.105.1
Commit: 7b98dcb824ea96c9c62362a5e80dbf0d1aae4770
Date: 2026-02-17T05:58:33.110Z
Build Type: Stable
Release Track: Default
Electron: 39.3.0
Chromium: 142.0.7444.265
Node.js: 22.21.1
V8: 14.2.231.22-electron.0
OS: Darwin arm64 24.6.0

For AI issues: which model did you use?

Auto

Does this stop you from using Cursor

No - Cursor works, but with this issue

Oddly if I run the IDE from my terminal and set an explicit JAVA_HOME variable, java -version works inside the sandbox.

JAVA_HOME=/Users/me/Library/Java/JavaVirtualMachines/temurin-21.0.5/Contents/Home cursor .

Hey, thanks for the detailed report.

This looks like a macOS sandbox limitation. /usr/libexec/java_home uses specific system paths for JDK discovery, and the sandbox blocks access to them. Glad you found a workaround with JAVA_HOME.

A few options:

  1. Set a permanent JAVA_HOME. Add this to ~/.zshrc or ~/.bash_profile:
export JAVA_HOME=/Users/me/Library/Java/JavaVirtualMachines/temurin-21.0.5/Contents/Home

Then restart your terminal and open Cursor via cursor . so the sandbox inherits the variable.

  1. Symlink inside the workspace (like you already did). If you need different versions per project, you can add a symlink in the project root and point the agent to ./runjava25 instead of java.

  2. Legacy Terminal Tool. Try switching to the legacy terminal (Cursor Settings > Agents > Legacy Terminal Tool). The sandbox works differently there and might not block java_home.

Let me know if the workaround doesn’t fit your setup or if you want help configuring it.

This topic was automatically closed 22 days after the last reply. New replies are no longer allowed.