Shellbox
Library and server for containerized shell execution
Loading...
Searching...
No Matches
Shellbox\Shellbox Class Reference

Static factories and miscellaneous utility functions. More...

Static Public Member Functions

static createBoxedExecutor ( $config=[], LoggerInterface $logger=null)
 Create a LocalBoxedExecutor from a configuration array.
 
static createUnboxedExecutor ( $config=[], LoggerInterface $logger=null)
 Create an UnboxedExecutor from a configuration array.
 
static createTempDirManager ( $tempDirBase=null)
 Create a TempDirManager from a shared base path (e.g.
 
static escape (... $args)
 Escape arguments for the shell.
 
static getMaxCmdLength ()
 Get the platform's maximum command length in bytes, minus a safety margin.
 
static getUniqueString ()
 Get a random string from a CSPRNG.
 
static jsonEncode ( $value)
 JSON encode with our preferred options.
 
static jsonDecode ( $json)
 Throwing wrapper for JSON decode with our preferred options.
 
static normalizePath ( $path)
 Validate a relative path for path traversal safety and cross-platform file name compliance.
 

Detailed Description

Static factories and miscellaneous utility functions.

Member Function Documentation

◆ createBoxedExecutor()

static Shellbox\Shellbox::createBoxedExecutor ( $config = [],
LoggerInterface $logger = null )
static

Create a LocalBoxedExecutor from a configuration array.

This can be used to run commands locally, without the client/server split.

Parameters
array$configAssociative array of configuration parameters:
  • tempDir: The parent directory in which a temporary directory may be created
  • useSystemd: If true, systemd-run will be used
  • useBashWrapper: If true, limit.sh will be used
  • useFirejail: If true, firejail will be used
  • firejailPath: The path to the firejail binary
  • firejailProfile: The path to the firejail profile
  • cgroup: A writable cgroup path which can be used for manual memory limiting
LoggerInterface | null$logger
Returns
LocalBoxedExecutor

◆ createTempDirManager()

static Shellbox\Shellbox::createTempDirManager ( $tempDirBase = null)
static

Create a TempDirManager from a shared base path (e.g.

/tmp)

Parameters
string | null$tempDirBase
Returns
TempDirManager

◆ createUnboxedExecutor()

static Shellbox\Shellbox::createUnboxedExecutor ( $config = [],
LoggerInterface $logger = null )
static

Create an UnboxedExecutor from a configuration array.

This can be used to run commands locally, without temporary directory setup or the client/server split.

A temporary directory is only needed if the command runs on Windows.

Parameters
array$configAssociative array of configuration parameters:
  • tempDir: The parent directory in which a temporary directory may be created
  • useSystemd: If true, systemd-run will be used
  • useBashWrapper: If true, limit.sh will be used
  • useFirejail: If true, firejail will be used
  • firejailPath: The path to the firejail binary
  • firejailProfile: The path to the firejail profile
  • cgroup: A writable cgroup path which can be used for manual memory limiting
LoggerInterface | null$logger
Returns
UnboxedExecutor

◆ escape()

static Shellbox\Shellbox::escape ( $args)
static

Escape arguments for the shell.

Parameters
mixed|mixed[]...$args strings to escape and glue together, or a single array of strings parameter. Null values are ignored.
Returns
string

◆ getMaxCmdLength()

static Shellbox\Shellbox::getMaxCmdLength ( )
static

Get the platform's maximum command length in bytes, minus a safety margin.

Returns
int

◆ getUniqueString()

static Shellbox\Shellbox::getUniqueString ( )
static

Get a random string from a CSPRNG.

Returns
string
Exceptions

Exception

◆ jsonDecode()

static Shellbox\Shellbox::jsonDecode ( $json)
static

Throwing wrapper for JSON decode with our preferred options.

Parameters
string$json
Returns
mixed

◆ jsonEncode()

static Shellbox\Shellbox::jsonEncode ( $value)
static

JSON encode with our preferred options.

Parameters
mixed$value
Returns
string

◆ normalizePath()

static Shellbox\Shellbox::normalizePath ( $path)
static

Validate a relative path for path traversal safety and cross-platform file name compliance.

Under Windows, the path may contain backslashes, which will be replaced with slashes.

Parameters
string$path
Returns
string
Exceptions
ShellboxError

The documentation for this class was generated from the following file: