Do not have permission to open the file

In macOS, I am encountering an issue where the system API fails to grant permission to open a file despite enabling the necessary Read/Write permissions within the SandBox. Could you please elucidate the reasons behind this behavior? Thanks!

func finderOpenFileSystem(at path: String) {
    let fileURL = URL(fileURLWithPath: path)
    
    guard FileManager.default.fileExists(atPath: path) else {
        print("Error: File does not exist at path: \(path)")
        return
    }
    
    let success = NSWorkspace.shared.open(fileURL)
    if success {
        print("File opened successfully: \(fileURL)")
    } else {
        print("Error: Failed to open file: \(fileURL)")
    }
}

Do not have permission to open the file
 
 
Q