Not to be confused with sandbox games.
(tl;dr: Games would benefit from sandboxing simply due to amount of different games there are. However, sandboxing a game is non-trivial for a player, so we as developers should think of ways to make our games easy to run sandboxed.)
Sandboxing (isolating from parts of the system in hopes of security benefits) games is something I've thought a lot about lately and I'd be curious to know if anyone else has any thoughts on this. I've added some of mine below.
Why should games be sandboxed?
The main thing that makes me want to sandbox games specifically is the amount of different games I run, many of which aren't available in distro repos (which is also not a guarantee on non-maliciousness, much less non-vulnerability). And while sandboxing can't make running them perfectly safe, it would be nice to at least require malicious actors to put in more effort.
Apart from straight up malicious games, games can also have vulnerabilities (see here for example), which a sandbox could help mitigate. And of course, some games have a system of loading third party mods which the original dev hasn't audited.
Another thing about games is that they typically should only need to access a small part of the filesystem – their own config and savegames plus some read-only access to some libraries etc. Restricting them to that just seems prudent.
How to sandbox games as a player?
Sandboxing is part of the core packaging model of both Flatpak and Snap, so software installed through them may be effectively sadboxed out of the box. I say "may" however, since you can't trust them blindly. For example, Flatpak will happily give an installed package whatever extra access rights it requests. Snap sandoxing uses AppArmor becoming ineffective if that isn't available.
Websites are sandboxed by browsers as a matter of course, so web games are also automatically sandboxed. Pesonally, browser sandboxes are among the ones I find the easiest to trust as they are protecting countless people against loads of untrusted code every day. Using them, of course, requires there to be a web port of the game that then has to suffer the limitations of the platform.
There are also some standalone sandboxing programs, Firejail being the perhaps best-known example. Pre-made profiles exist for some programs, but in practice you'll end up writing your own, and my experience with that hasn't been great. To get the best possible sandbox, you'll want to start by forbidding as much as possible, which unfortunately does not tend to be the default state. And only after getting that sorted do you get to start the painstaking process of figuring out what rights the sandboxed program actually needs.
The biggest hammer in the sandboxing toolbox are virtual machines. VMs certainly provide the most isolation while still running on the same machine. This comes at the cost of performance, especially for graphics and thus games. Native contexts might however improve the situation.
How to sandbox games as a developer?
So, sandboxing as the end user is a pain. Could we as developers provide an easy way to sandbox our games? I could see providing the extra security and being easier to trust being worth the effort.
Providing Flatpak and/or Snap packages and/or web ports is the only standardised way I know of providing your software pre-sandboxed in a way verifiable at a glance (assuming you trust the sandbox of course). I have considered proving Firejail or or AppArmor profiles, but that would require extra action on the user side, meaning the effort would only end up benefiting a minority of users. I also fear such profiles would end up being too complex to check easily, reducing the trust benefit.
Certainly any game processing untrusted input, especially code-executing mods, should consider sandboxing itself somehow. I'll mention Landlock, which is a new(-ish) way for a Linux process to restrict itself, but other methods exist as well.
Again, I'd be curious to know if anyone else has any thoughts on this and what they might be.