# End-to-end automation

This example creates a Laravel sandbox, changes its home page, verifies the change, and returns a preview URL.

## Create a Laravel sandbox

```ts
import { PHPSandbox } from '@phpsandbox/sdk';

const client = PHPSandbox.realtime(process.env.PHPSANDBOX_TOKEN!);

const sandbox = await client.notebook.create('laravel', {
  title: 'Laravel product demo',
  visibility: 'unlisted',
});
```

The SDK currently exposes sandbox operations through `client.notebook`. The resource it creates is a sandbox throughout this documentation.

## Make a change

```ts
await sandbox.files.write(
  'resources/views/welcome.blade.php',
  '<h1>Welcome to our product demo</h1>',
);
```

For an existing product, read the current file and make the smallest useful change instead of replacing unrelated content.

## Verify the result

```ts
const result = await sandbox.exec('php artisan test');

if (result.exitCode !== 0) {
  throw new Error(result.stderr || result.output);
}
```

Use `exec()` when you need the completed result. Use `run()` when output must be handled while a command is still running.

## Return the preview

```ts
const ready = await sandbox.ready();

console.log({
  sandboxId: sandbox.data.id,
  previewUrl: ready.data.previewUrl,
});
```

The sandbox remains available for review, feedback, or further work. Delete it only when the workflow itself requires a temporary sandbox.
