PHP code example of cyclechain / sandboxer

1. Go to this page and download the library: Download cyclechain/sandboxer 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/ */

    

cyclechain / sandboxer example snippets


'auto_detection' => [
    'domains' => 'demo.*.com,sandbox.*.com,try.*.com',
    'paths' => '/demo,/sandbox,/try',
    'parameters' => ['sandbox' => '1', 'demo' => 'true'],
],

use Cyclechain\Sandboxer\Helpers\SandboxAuthHelper;
use Illuminate\Http\Request;

public function login(Request $request)
{
    // Handle demo/sandbox login credentials transparently
    $sandboxResponse = SandboxAuthHelper::handleSandboxLogin($request, '/dashboard');
    if ($sandboxResponse) {
        return $sandboxResponse;
    }

    // Normal application login flow
    return parent::login($request);
}

use Cyclechain\Sandboxer\Facades\Sandboxer;

// Check if sandbox mode is active for current request
if (Sandboxer::isActive()) {
    // Current request is sandboxed
}

// Get the current sandbox session UUID
$sandboxId = Sandboxer::currentId();

// Manually destroy current sandbox session and clear storage
app(\Cyclechain\Sandboxer\SandboxManager::class)->destroy();

use Illuminate\Support\Facades\Schedule;
use Cyclechain\Sandboxer\Jobs\SandboxCleanupJob;

Schedule::job(new SandboxCleanupJob())->hourly();

return [
    'enabled' => env('SANDBOXER_ENABLED', false),
    'ttl' => env('SANDBOXER_TTL', 3600),

    'demo_credentials' => [
        'email' => env('SANDBOXER_DEMO_EMAIL', '[email protected]'),
        'password' => env('SANDBOXER_DEMO_PASSWORD', 'admin'),
    ],

    // Tables excluded from sandboxing (e.g. system/auth tables)
    'excluded_tables' => ['users', 'sessions', 'password_reset_tokens', 'migrations', 'sandbox_sessions', 'sandbox_storage'],

    'cache' => [
        'enabled' => env('SANDBOXER_CACHE_ENABLED', true),
        'prefix' => env('SANDBOXER_CACHE_PREFIX', 'sandbox'),
        'ttl' => env('SANDBOXER_CACHE_TTL', 3600),
    ],

    'auto_detection' => [
        'domains' => env('SANDBOXER_AUTO_DOMAINS', 'demo.*.com,sandbox.*.com,try.*.com'),
        'paths' => env('SANDBOXER_AUTO_PATHS', '/demo,/sandbox,/try'),
        'parameters' => ['sandbox' => '1', 'demo' => 'true'],
    ],

    'cleanup' => [
        'enabled' => env('SANDBOXER_CLEANUP_ENABLED', true),
        'interval' => env('SANDBOXER_CLEANUP_INTERVAL', 3600),
    ],
];
bash
php artisan vendor:publish --tag=sandboxer.config
bash
php artisan migrate
bash
php artisan queue:work