Limiting access of a Script/Class

Godot Version

3.5.3-stable

Question

I’m trying to add modding support to my game, thinking of either making it with GDScript or perhaps some lua extension, the problem is that modders would have access to things like OS related functions and classes that manage the game in ways it could break when irresponsibly modded. Is there any way I can limit what singletons/classes a script/class can call? I would much rather expose an API specific for modding with it’s own signals and methods. Thank you very much in advance.

You’re in for a world of hurt. I don’t think this is even possible. Can other engine’s do this?

Your best bet would be to be open about how mods can be malicious and solve the problem on a social-level. You may have to vet mods manually and probably force your game to only fetch mods from some single, controllable repo.

After seeing this post, I had found an open issue on GitHub for adding this. I came back here to share it, but then I realized I didn’t have it in my history (was on mobile and it opened in the GitHub app), and can’t find it for some reason. I’ll keep looking, but if anyone else sees the issue I would appreciate the link :slight_smile:

Just found it after a lot of searching, though I feel like this may be a different proposal than the one I initially saw, but still same idea:

Edit: just saw this one that was referenced from that one, which I think was the one I originally saw:

There was a very related discussion topic not that long ago

Hey that’s me!

Just for clarification, the approach I plan on using and discuss on my post is rather an “addon” system and not a modding system. Sandboxing imported scenes and scripts seems feasible, but modding is a whole different beast. As I mention, for modding, I use Godot Mod Loader, which is not sandboxed and probably won’t be in the near future, as Godot in general.

Sandbox is a complicated topic mostly because it requires much more customization than I expected at first glance. For an agnostic engine, like Godot, how would you decide on what should be restricted or not in a sandbox? Clearly there’s a need to specify your own limits through an API for each specific case. Apart from all the technical challenges of actually isolating a program at a system level, which is truly sandboxing. Still, Godot is also used for actual applications and not just games, so not everyone would benefit from sandbox, and Godot PRs like their features to be apt for everybody!

Godot native sandboxing is going to take a looong while, just guessing. In the mean time, if you want a true sandbox, check godot-sandbox. However, it is not a simple library! And honestly, you seem like just wanting mod support, for what GML seems more than enough. If your mods are going to be downloaded manually by the users and loaded on startup, yeah, just use the loader :smiley: . We’ve all been downloading mods for years exposing ourselves to the risk of malicious intent, it’s a risk we accept and usually, if you’ve got your 101 internet course, nothing bad will ever happen. Finally, if you want your mods to be automatically downloaded at runtime (something more akin to UGC items), you can try my approach.