Docs / Plugins / Writing plugins
Permissions and sandbox
Permissions#
| Permission | Allows |
|---|---|
ui |
panels, messages, notifications, cables, screenshots |
storage |
omsi.storage and omsi.files |
vehicle_write |
driving the player's bus: variables, triggers, doors, IBIS |
traffic_write |
changing AI traffic, people and other vehicles |
world_write |
time, weather, duty, teleport, game commands |
camera |
moving the camera |
audio |
playing sounds |
network_local |
omsi.send (UDP to this computer) |
network_remote |
omsi.ws (read-only feeds to hosts the player allows) |
lan |
sending in a LAN session, reading the host's session details |
process |
starting native helper programs |
native |
full access to the computer (see Full access) |
- A plain
.luaplugin has every permission butnative, which the player gives. - A compiled
.oophas only the permissions it declares. A function that needs another one raises an error the plugin can catch. An unknown permission name grants nothing. - Vehicle scripts have only
ui,storage,vehicle_writeandaudio. - Reading the game needs no permission.
network_remotealso needs the player to allow each WebSocket host inwebsocket-hosts.txtin the plugins folder. Nothing is sent to those servers.processalso always needs the player's approval for each helper.
omsi.plugin.permissions() lists what the plugin has. The API reference names the permission of each function.
The Lua sandbox#
The sandbox below holds for every plugin without full access. A plugin the player trusts leaves it: see Full access.
A Lua plugin gets Lua 5.4 with the safe libraries only: string, table, math, utf8, coroutine, require for its own folder, and os.clock, os.time, os.date, os.difftime.
- No
io, noos.execute(not throughrequire("os")either), no C modules, nodofileorloadfile. - No binary chunks anywhere. Plugin files, modules and
loadread text only, because Lua does not check compiled code.string.dumpgives no code. - A plugin writes files only in its data folder, and reads only that and its own folder.
..and absolute paths are refused. - It cannot reach the network except for read-only WebSocket feeds to hosts the player allowed in
websocket-hosts.txt.omsi.sendtalks only to programs on this computer, on ports from 1024 up. - It holds at most 256 MB of memory.
Errors and limits#
- An error in a handler is written to
game.logand shown on the screen. The other plugins and the game carry on. - After 10 errors the plugin is switched off until you change its file or restart the game.
omsi.plugin.errors()counts them. - A call into the plugin that runs longer than 50 ms (an endless loop, say) is stopped and the plugin switched off, with a line in
game.log. Loading may take up to a second. - A file that does not compile is left out, with the Lua error in
game.log. omsi.plugin.disable(reason)switches a plugin off by its own choice.
Native helper programs#
omsi.process.start("bin/helper.exe", args, options) starts a program from the plugin's own folder. For a plugin without full access this is the only way out of the sandbox, so the player decides every time.
The approval window. The first time a plugin tries to start a helper, the game asks. The window shows the plugin's name, the program's file name and the number of arguments, with a safety warning. Details shows the full program path, the plugin's entry file, every argument and the working directory; Hide details folds them again. Opening the details never approves anything.
| Button | Effect |
|---|---|
| Allow once | this one start |
| Always allow | saved, bound to this plugin's code and this helper |
| Deny | no helpers for this plugin until the game restarts |
Esc also denies; Enter never approves. The game and other plugins keep running while the window waits. Reloading or unloading the plugin cancels the request. The window is translated into every interface language; plugin names, paths and arguments are shown literally.
What "Always allow" binds to. The approval is saved in ~/.openomsi/plugin-process-permissions.json. It covers the plugin's entry file, its folder's executable content (Lua modules, native .dll, .so, .dylib libraries and, for a folder plugin, the other package files) and the helper, each by SHA-256.
Changing any of these, or moving the plugin, asks again. Saved data (*.save.lua, non-executable files in data/ or *.data/) is not included, so omsi.save(), omsi.storage and omsi.files do not invalidate it.
For a one-file plugin in the top-level plugins folder, sibling Lua files are included because require can load them; use a folder plugin to keep them apart. To revoke an approval, close the game and remove it from that file.
Deny blocks every helper of that plugin for the rest of the session, even if the helper's name, content or arguments change.
Rules for helpers:
filemust be a relative path inside the plugin's folder. On Windows it must be an.exe, not a script.argsare separate literal strings; there is no shell.optionsmay setcwdandenv(overrides; other variables are inherited).OMSI_PLUGIN_PROCESS_ALLOWis always removed from the helper's environment.- Standard input and output are disconnected.
- A compiled plugin must also declare the
processpermission. - Helpers run with the player's account rights. The hash check is not a sandbox and not a lock: approved code can choose its arguments, working directory and environment.
Handles and waiting. process.start returns a handle at once; the check and the start happen on background workers. At most 32 starts are queued in the whole game, and each plugin has at most 32 handles (queued and failed ones count). A request that cannot be queued returns nil and a reason.
One that fails later shows it in process.status(h).error, or nil, "failed", reason from exit_code and wait. pid is nil until the program runs. Requests are limited to 256 arguments, 128 environment overrides and 64 KiB of text.
process.status and process.exit_code never block. In Lua, process.wait(h) suspends the plugin's current top-level callback (the main chunk, an event handler or a timer) until the helper exits, while the game and other plugins go on. Callbacks that arrive meanwhile wait (up to 256).
A nested emit handler or a hand-made coroutine cannot wait. Call process.forget(h) when you are done with a finished handle.
Cleanup. Stopping, disabling or reloading the plugin cancels pending waits and ends its helpers.
| System | Cleanup |
|---|---|
| Windows | a job object ends the helper and its children, even if the game crashes; forget also ends leftover children |
| Linux | the direct helper gets a signal when the game exits; its children do not |
| macOS | only normal plugin shutdown |
On macOS, a helper unpacked from a ZIP may need its executable bit (chmod +x /path/to/helper) and may be blocked by Gatekeeper quarantine. Check the helper and use macOS's normal approval; the game does not remove the quarantine.
Pre-approval (advanced). The environment variable OMSI_PLUGIN_PROCESS_ALLOW can name an absolute path to a JSON manifest of pre-approved plugins and helpers, for example on a managed machine. Generate it from the deployed plugin with the repository's tool, and keep it outside the plugin folder:
cargo run -p omsi-plugin --bin omsi-plugin-grant -- /plugins/example/plugin.lua /plugins/example bin/helper.exe > /plugins/process-grants.jsonFor an .oop, the entry is the archive and the folder is its extracted asset folder (or the archive's folder when it has no assets). Several entries go in the manifest's grants list. The game still re-checks every hash before each start. Grants from an older full-folder snapshot may need approval once more.
Something wrong or missing? Fix it on GitHub or open an issue.