> ## Documentation Index
> Fetch the complete documentation index at: https://docs.instructorphp.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Sandbox run php script

## Overview

Run inline PHP in sandboxed execution.
Useful when tools need controlled script execution with predictable policy limits.

## Example

```php theme={null}
<?php
require 'examples/boot.php';

use Cognesy\Sandbox\Config\ExecutionPolicy;
use Cognesy\Sandbox\Enums\SandboxDriver;
use Cognesy\Sandbox\Sandbox;

$policy = ExecutionPolicy::in(__DIR__)
    ->withTimeout(5);

$sandbox = Sandbox::fromPolicy($policy)->using(SandboxDriver::Host);

$result = $sandbox->execute([
    'php',
    '-r',
    'echo "sandbox says hi\\n"; echo "cwd=" . getcwd() . "\\n";',
]);

echo $result->stdout();

assert($result->exitCode() === 0, 'PHP script should exit with code 0');
assert(str_contains($result->stdout(), 'sandbox says hi'), 'Output should contain expected greeting');
?>
```
