SDK
Markdown

TypeScript SDK 0.1.10

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

TypeScript
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

TypeScript
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

TypeScript
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

TypeScript
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.

Loading templates

You can also reach out on Twitter or Discord if you need help.