The Roll20 Mod Script Sandbox functions by running a special server-side virtual machine for each campaign. This provides a sandbox where your custom scripts can run without any danger of them affecting other users’ campaigns. In addition, this provides a layer of security which prevents a malicious GM from writing scripts which could do bad things like access a player’s computer or stall their computer with an infinite loop.
Mod Script Sandbox v1.0 and v1.5 use this same model. v1.5 exposes additional functions and object methods inside the sandbox.
How it Works
If you’re curious in the technical details of how the sandbox functions, here’s a brief diagram:
User-written scripts ===> Mod Script Server ===> Campaign Sandbox <===> Real-Time Sync Server
The Mod Script Server listens for activity on your campaign. When it detects that people are using your campaign, it spins up a sandbox for your campaign and loads any Mod Scripts that you have written into the sandbox. The sandbox can receive and send data directly to the real-time sync server, which allows it to respond to events and make changes to the game.
Restrictions from Normal Javascript
While Roll20 scripts are Javascript, there are some restrictions you should be aware of if you’re used to programming Javascript for websites. Roll20 scripts are executed in a separate sandbox from the Roll20 site. This provides an additional layer of separation and security for our system and your players. This sandbox means that:
- You cannot make HTTP Requests (AJAX).
- You cannot load external scripts or libraries (e.g. jQuery). You do have the Underscore.js library (via the
_global object). - The environment is Javascript, but it is not an environment in a browser, so there is no DOM, page elements, CSS,
document,window, etc.