1. Go to this page and download the library: Download shipfastlabs/bashbox library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
shipfastlabs / bashbox example snippets
use BashBox\Bash;
$bash = new Bash;
$result = $bash->exec('echo "Hello, World!"');
$result->stdout; // "Hello, World!\n"
$result->exitCode; // 0
use BashBox\ExecOptions;
$result = $bash->exec('grep "error"', new ExecOptions(
stdin: "line 1\nerror found\nline 3\n",
));
$result->stdout; // "error found\n"
use BashBox\Bash;
use BashBox\BashOptions;
use BashBox\Limits;
$bash = new Bash(new BashOptions(
limits: new Limits(
maxCommandCount: 100,
maxLoopIterations: 500,
maxOutputSize: 1024 * 1024, // 1MB
maxCallDepth: 10,
),
));
use BashBox\Commands\AbstractCommand;
use BashBox\Commands\CommandContext;
use BashBox\ExecResult;
class MyCommand extends AbstractCommand
{
public function getName(): string
{
return 'mycommand';
}
public function execute(array $args, CommandContext $ctx): ExecResult
{
return $this->success('Hello from my command!');
}
}
$bash->registerCommand(new MyCommand);
$result = $bash->exec('mycommand');
$result->stdout; // "Hello from my command!"
use BashBox\Bash;
use BashBox\BashOptions;
use BashBox\Filesystem\InMemoryFs;
use BashBox\Filesystem\OverlayFs;
use BashBox\Filesystem\ReadWriteFs;
use BashBox\Filesystem\MountableFs;
// In-memory (default) — nothing touches disk
$bash = new Bash;
// Overlay — reads from a real directory, writes stay in memory
$bash = new Bash(new BashOptions(
fs: new OverlayFs('/path/to/project'),
));
// Read-write — real disk I/O via amphp/file
$bash = new Bash(new BashOptions(
fs: new ReadWriteFs('/path/to/sandbox'),
));
// Mountable — combine multiple backends at different paths
$mount = new MountableFs(new InMemoryFs);
$mount->mount('/data', new ReadWriteFs('/real/data'));
$bash = new Bash(new BashOptions(fs: $mount));
$bash = new Bash(new BashOptions(
fs: new ReadWriteFs('/path/to/sandbox'),
));
$bash->exec('echo "#!/bin/bash" > /script.sh');
$bash->getFilesystem()->chmod('/script.sh', 0755);
$stat = $bash->getFilesystem()->stat('/script.sh');
$stat->mode; // 0755
$stat->size; // file size in bytes
use BashBox\Bash;
use BashBox\BashOptions;
use BashBox\Network\NetworkConfig;
$bash = new Bash(new BashOptions(
network: new NetworkConfig(
allowedUrlPrefixes: ['https://api.example.com/'],
allowedMethods: ['GET', 'POST'],
denyPrivateRanges: true, // SSRF protection
maxResponseSize: 5 * 1024 * 1024, // 5MB
maxRedirects: 10,
timeout: 10,
),
));
$result = $bash->exec('curl -s https://api.example.com/data');
use BashBox\Bash;
use BashBox\BashOptions;
use BashBox\Network\NetworkConfig;
$bash = new Bash(new BashOptions(
network: new NetworkConfig(
dangerouslyAllowFullInternetAccess: true,
// denyPrivateRanges still protects against SSRF attacks
denyPrivateRanges: true,
maxResponseSize: 5 * 1024 * 1024, // 5MB
maxRedirects: 10,
timeout: 10,
),
));
// Now any URL and HTTP method is allowed
$result = $bash->exec('curl -X POST https://any-website.com/api');