Repository navigation
Scripting Architecture
000hen edited this page Jul 7, 2026
·
2 revisions
JustHostMC's scripting environment uses a locked-down gopher-lua interpreter to safely run third-party server providers and automation scripts.
Every script runs in a highly restricted sandbox:
-
Safe standard libraries only: Access is granted to
base,table,string, andmath. -
No dangerous libraries: The
os,io,package/require,debug, andcoroutinelibraries are completely omitted. -
Escape hatches removed: Potentially dangerous functions in the base library like
dofile,load,loadfile, andrequireare deleted. -
Strict Filesystem Confinement: All filesystem access (via the
jhmc.fs.*host API) is strictly confined to the server's working directory. The engine prevents path traversal (e.g.,../) and provides zip-slip protection.
The execution model guarantees isolation:
-
Providers: Each provider invocation (e.g., calling
versions()orinstall()) receives a fresh interpreter state. State cannot leak between calls. - Automation: Automation scripts are allocated a long-lived, dedicated LState. Because gopher-lua is not safe for concurrent use, all automation event hooks are strictly serialized onto a single goroutine by the engine.
The scripting engine maintains several data stores on disk:
-
GrantStore (
*-grants.json): Persists the permission consent decisions for third-party scripts. Different script types use their own files (e.g.,grants.jsonfor providers,script-grants.jsonfor automation,parser-grants.jsonfor parsers,shop-grants.jsonfor shops). -
KV Store (
script-data/*.json): Each automation script is allocated an isolated, persistent Key-Value store mapped tojhmc.store.*to save cursors, counts, and other runtime data across engine restarts.
When a Provider script finishes downloading and configuring a server, it returns a launch specification containing the required Java version (java_major) and startup arguments (args).
The engine passes this specification to its Isolation Layer, which manages the server process:
- Backends: The isolation layer uses Windows Job Objects (on native Windows setups) or the Docker Backend (if Docker is present and enabled).
-
Resource Limits: The isolation layer enforces hard memory caps (
MemoryMB) and tracks live telemetry independently of the Lua script. -
Metrics (Stats): The backend samples metrics such as
CPUPercent,MemoryBytes, andNetRxBytesPerSec, forwarding them to the JustHostMC UI.
- Back to the Scripting Hub