Skip to main content

Sandboxing Technical Details

How does the sandbox work under the hood?

Written by Josh

If you're looking for a general explanation of how sandboxing works, see our Understanding Sandboxing article.

What is Sandboxed

The sandbox is designed to be as permissive as possible in terms of interacting with your system. It doesn’t block network requests (unless the user changes a setting), it allows access to all USB devices (mouse, keyboard, webcam, controllers), it allows access to programs on $PATH, etc.

The big restriction of the sandbox is around files - only system files, files required for Minecraft to run, folders whitelisted by the user in the launcher and files/folders which are picked from a file dialog/drag-and-dropped are accessible.

We are constantly trying to improve the sandbox, so if there is some file/folder/socket your mod needs access to then let us know and we’ll try to work out a solution.

Some mods allow the user to choose a custom directory to store files, e.g. mods like Litematica, WorldEdit or Axiom might allow you to use a custom folder to store schematic files in. For now, if a user picks a custom location on their computer, they may also need to grant access to that folder inside the launcher’s sandbox settings.

Some mods (e.g. horror mods or challenge mods like ‘every time you die a random file is deleted’) can have functionality that intentionally messes with your system in dangerous and unpredictable ways. Unfortunately, this kind of behavior can be very difficult to distinguish from malware and will be prevented by the sandbox.

Depending on your platform, it may not be possible to grant access to certain functionality. For example, on Windows the Discord RPC system uses a Named Pipe. Unfortunately, Windows has no mechanism to allow the Named Pipe to be exposed to the AppContainer and as such the sandboxed game will not be able to communicate with the discord client.

Detecting the Sandbox

You can check for the INSIDE_MODRINTH_SANDBOX environment variable.

Isolated Folders

Various folders have been redirected to isolated locations. This includes: $HOME, $XDG_DATA_HOME/$XDG_CONFIG_HOME/$XDG_CACHE_HOME/$XDG_STATE_HOME on Linux and $APPDATA and $LOCALAPPDATA on Windows. Temp folders (/tmp, TEMP, TMP, TMPDIR, etc.) are also isolated.

As a mod developer, you can use these isolated folders for storing data across sandboxed instances. However, if the user then disables sandboxing these environment variables will go back to pointing at their old locations.

No Permission System

One common question that gets asked by developers is “why is there no permission system that allows mods to request access to certain functionality or files.” There are a few reasons: firstly, the sandbox operates over the whole process so any permission granted to one mod would be available to all other mods.

Secondly, a permission system would create unnecessary burden on mod developers - we want everything to work out-of-the-box without any configuration from developers.

Thirdly, a permission system would potentially make it easier for malware to trick users into giving access to sensitive files. As an example, imagine a malicious mod that requests access to 10 benign files, but then right at the end asks for access to the stored credentials in your browser. The trick is that users will just end up spam clicking “Accept,” and not notice the sneaky request at the end.

Instead of a permission system, as explained in the section “What is sandboxed,” the approach taken is to simply be as permissive as possible by default and hopefully cover the majority of mods.

Blocked Folders

Some folders may be blocked entirely from being accessible or being written to, even when the user adds the path to the launcher configuration.

One example of such a path is the Windows Documents folder, which can only be given read access and not write access. This is because the Documents folder contains the PowerShell folder which can lead to code execution outside the sandbox if written to.

Other examples include folders that are typically targeted by malware like browser and Discord credential folders.

Authentication

The sandbox attempts to make it more difficult for malicious mods to steal your Minecraft account. The primary way it does this is by passing a fake access token to the game and then running a proxy to handle authentication calls. Any authentication request containing the fake access token is replaced by the real access token.

If you’re a mod developer and manually try to use the game’s access token make authentication requests, you’ll get the fake access token instead and the request will fail. Instead, make sure you use Mojang’s authlib library or make sure you handle the minecraft.api.xyz.host system properties correctly.

Of course, this layer of protection does not completely prevent a malicious mod from logging in on your behalf, it just prevents the exfiltration of the access token itself.

As an added layer of protection, server owners can enable prevent-proxy-connections in the server.properties file to prevent connections from IPs that don't match the IP that was used to authenticate.

Backends

The sandboxing implementation has 4 backends: AppContainers (Windows), seatbelt (macOS), Bubblewrap (Linux), Flatpak (Linux when launcher is running inside flatpak).

Sandbox Java Agent

The sandbox uses a java agent to transform various classes to ensure everything is working correctly. Transformations include: authlib 1.x supporting the minecraft.api.xyz.host properties, realms is transformed to use our proxy instead of the hardcoded endpoint, SDL/NFD/TFD file dialogs are forwarded to the launcher (see below), various ‘open uri’ calls are forwarded (Blaze3D, Util$OS, java.awt.Desktop, Runtime#exec).

Some transformations may be disabled on certain platforms. For example, macOS’s sandboxing handles file dialogs correctly without needing forwarding, so the transformation is disabled on macOS.

File Dialogs

File dialogs should be caught by the sandbox agent and forwarded to the launcher. The launcher then is able to grant the sandbox access to any files chosen by the user through the file dialog. Currently, this access is not persisted between sessions.

Drag-and-drop

Drag-and-drop functionality varies significantly between platforms. Often, dropping a file just gives the game the raw path which may not be accessible. To ensure a smooth experience, we need to dynamically expose that path to the game.

On Windows, we use a special workaround that intercepts a drag-and-drop operation with an overlay, then forwards the drag-and-dropped file to the game after granting permission to the file.

On Linux Wayland, certain windowing systems like SDL (Minecraft 26.3+) use the flatpak document portal system to receive access to the drag-and-dropped file. Older windowing systems like GLFW (Minecraft 26.2 and below) may not use this system, in which case they fall back to the X11 behaviour.

On Linux X11, we have no way of validating that the drag-and-dropped file is legitimate. Instead, our best option is to have the game request arbitrary file access from the launcher. The catch is that the launcher only allows access to certain file formats it deems safe: resourcepacks, datapacks, flashback replays, schematics, etc. If your mod needs to accept arbitrary files from drag-and-drop, unfortunately it won’t work on Linux X11.

On macOS, we don’t need any workarounds. Seatbelt automatically grants access to files that are drag-and-dropped into the Window.

Did this answer your question?