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, ?ClientInterface $urlFileClient=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.
 
static checkExtension ( $extension)
 Check an extension for path traversal safety and cross-platform file name compliance.
 

Detailed Description

Static factories and miscellaneous utility functions.

Member Function Documentation

◆ checkExtension()

static Shellbox\Shellbox::checkExtension ( $extension)
static

Check an extension for path traversal safety and cross-platform file name compliance.

Throw an exception if it is not acceptable.

Since
4.1.0
Parameters
string$extension
Exceptions
ShellboxError

◆ createBoxedExecutor()

static Shellbox\Shellbox::createBoxedExecutor ( $config = [],
?LoggerInterface $logger = null,
?ClientInterface $urlFileClient = 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
  • urlFileConcurrency: The maximum number of HTTP requests to have in flight, if BoxedCommand::inputFileFromUrl() and outputFileToUrl() were used.
LoggerInterface | null$logger
ClientInterface | null$urlFileClientAn HTTP client to use to implement BoxedCommand::inputFileFromUrl() and outputFileToUrl(). If this is null, using those features will result in an exception being thrown.
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: