Repository navigation
Deck: run save readers in a bubblewrap sandbox - #4
Merged
Alexsander720 merged 2 commits intoNov 30, 2026
Merged
Conversation
…deck deck_home() fell back to $HOME when /home/deck is absent, and main.py hard-coded /home/deck/homebrew for the Game Theme Music cache. On a desktop Linux install (Steam .deb, user is not "deck") the theme-music lookup could never match, and a backend started as root (HOME=/root) would find no library, prefix or save at all. deck_home() now tries, in order: /home/deck, the sudo invoker, the single /home/* account that owns a Steam installation, then $HOME. The theme music path is derived from it. Behaviour on a Steam Deck is unchanged. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Readers are plain Python modules imported into the backend; in-process they can do anything the backend user can (home, network, writes). This runs each read() in a short-lived bwrap child instead: - read-only: /usr, plugin/py_modules, and only the save locations for the reader's appid(s) (Proton prefix, Steam userdata, game install folder, libraryfolders.vdf, /etc/localtime); - --unshare-all (no network, own pid/ipc), --clearenv, tmpfs /tmp, --die-with-parent, 10 s timeout, 512 MB RLIMIT_AS in the child; - the child prints one JSON card; validate_card() keeps only the known keys, caps strings/lists/depth and coerces fact fields to strings. Appids come from the reader's APPID constants, parsed with ast (never imported), plus the appid being displayed. deck_home() honours a new CONTINUE_HOME override so the child resolves the same home as the host. Without bwrap or a system python3 (Windows, minimal images), or when the sandbox cannot start (user namespaces disabled), reads fall back to the previous in-process path; status() reports which, and the new backend method get_sandbox_status exposes it. Startup logs the status once. Measured on Decky 3.3.1 / Linux Mint: get_card round trip 30-45 ms with the sandbox, identical cards to the in-process reader. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Owner
|
Really appreciate you putting this together, and testing it on both Mint and an actual Steam Deck with timings. Having readers isolated in bubblewrap makes accepting community parsers way less scary, and it should help a lot if we submit to the Decky Store later. I went through all 25 existing readers in
If you want, I can push these fixes onto your branch so you can review them, or feel free to tweak it yourself. Thanks again for tackling this! |
Owner
|
Merged and shipped in v0.1.6, and the bubblewrap sandbox tests now run live in GitHub Actions too (v0.1.7). Thanks again for building this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As this is a bit more complex I want to add some explanation beforehand. First of all this is no random AI Slop :)
The current problem is that every game is a Python script that can do ANYTHING on your machine. As this is a project that relies on many contributors (for games) I personally think is close to impossible to review every Game-PR if it does something "bad" (like doing stuff in your filesystem instead of just reading savefiles).
Therefore I added a sandbox that makes sure it only can access files it should. Tested in Big Picture Mode (Linux Mint) and on Steamdeck
Now to the details:
Problem and result
Every reader in
ddsaves/is a Python module imported into the backend process. A reader can therefore do anything the backend user can: read the whole home directory, open network connections, write files. The proof gate already runs contributions in an isolated subprocess, but the shipping plugin runs the exported readers in-process.With this change each
read()runs in a short-lived bubblewrap child:/usr(system Python, openssl),plugin/py_modules, and the save locations for the reader's appid(s): Proton prefix, Steam userdata, game install folder,libraryfolders.vdf,/etc/localtime;--unshare-all(no network, own pid/ipc namespaces),--clearenv, tmpfs/tmp,--die-with-parent, 10 s timeout, 512 MBRLIMIT_ASin the child;validate_card()keeps only the card-contract keys, caps string/list sizes and nesting depth, and coerces fact fields to strings before anything reaches the frontend.The appids a reader may see come from its
APPIDconstants, parsed withast(never imported), plus the appid currently displayed.deck_home()gains aCONTINUE_HOMEoverride so the child resolves the same home as the host. Without bwrap or a systempython3, or when the sandbox cannot start (user namespaces disabled), reads fall back to the previous in-process path;status()says why, the new backend methodget_sandbox_statusexposes it, and startup logs it once.Scope
reader_sandbox.py,reader_sandbox_runner.py,deck_saves.py,ddsaves/_common.py,main.py)tests/test_reader_sandbox.py)Validation
reader sandbox {'sandboxed': True, 'bwrap': '/usr/bin/bwrap', 'python': '/usr/bin/python3', 'reason': None, 'fallbacks': 0}.get_cardfor a real save through Decky: 30–45 ms round trip, card identical to the in-process reader (facts andobserved_at;/etc/localtimeis bound so save timestamps keep local time)..ssh/canaryoutside it is invisible,socket.connectfails, writing next to the save fails,/root,/var,/optdo not exist.python -m unittest discover -s tests: 39 tests OK (6 new; the isolation tests skip where bwrap is absent).sandboxed: True,fallbacks: 0; the 6 sandbox tests pass on the Deck; the Graveyard Keeper 2 and Slay the Spire cards render as before (Steam Cloud saves undercompatdata/<appid>).get_cardround trip on the Deck is ~110 ms steady state (the sandboxed reader alone ~100 ms, of which nearly all is bwrap + interpreter start; the same reader in-process takes ~1 ms). On a Linux desktop the round trip is 30–45 ms.Remaining limits
main.pyand the frontend still run with the backend's privileges.