Which operating system do you mean? Flatpak has this already, Android enforces this kind of API for shared files, Windows UWP has pretty much the exact same API (https://learn.microsoft.com/en-us/uwp/api/windows.storage.pi...).

App developers will often choose not to sandbox their applications because it's a lot easier (and sometimes faster) do to all file management yourself, but the APIs are there and ready to be used.

Flatpak is probably the worst way to "have" this possible. It's completely opaque to both app and user. If you ever tried to run an .exe through flatpak'd bottles, you'll run into an issue where .dll's aren't found because you didn't install flatseal first to configure permissions. That's not operating-system level integration. That is actually very poor design that a user requires a separate app (flatseal) to configure how the sandbox works.

I was thinking about desktop OS's, actually.

You don't need to use that Windows API. You can just access any file you want. There is no reason a music player, for example, needs to access ~/Pictures. An arbitrary program requiring access to all your files is a huge red flag, but it's a red flag that users aren't allowed to see. Proper filesystem permissions would fix that.