Manual:Shell framework

MediaWiki provides a robust framework for shelling out to external commands for increased performance, security, and portability. See the documentation for and. A basic example:

Parameters
Most of the time you'll also want to provide some parameters to the command. MediaWiki will automatically escape all parameters to prevent shell injection attacks:

In the rare case you need to pass a parameter unscaped, you can use:

You can use  to manually escape parts of an unescaped parameter.

Limits
For both performance and security reasons, MediaWiki institutes limits on CPU time, wall clock time, file size and the memory usage a command can use. The defaults from, , , and will be used unless overriden with a call to.

Further restrictions can be implemented using cgroups, see for more details.

Restrictions
Since 1.31, MediaWiki supports sandboxing commands with external restriction software - currently only firejail is supported, and must be enabled with. You can pass any of the following constants to :
 * a convenience constant equivalent to
 * Disallow any root access. Any setuid binaries will be run without elevated access
 * Use seccomp to block dangerous syscalls
 * Create a private
 * Disallow any network access
 * Deny the execve syscall with seccomp

You can look at the restriction of binaries in the Score extension as an example.

Logging
By default, errors and standard error output are logged to the  channel in a structured form. A different logger can be set via the standard PSR-3.