SDK
Markdown

TypeScript SDK 0.1.10

Managing sandboxes

The SDK can create, retrieve, fork, stop, restart, and delete a sandbox. These operations act on the sandbox as a whole.

Create a sandbox

TypeScript
import { PHPSandbox } from '@phpsandbox/sdk';

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

const sandbox = await client.notebook.create('laravel', {
  title: 'Inventory',
  visibility: 'private',
});

The current SDK method is named client.notebook.create(), but the resource it creates is a sandbox.

Retrieve an existing sandbox

TypeScript
const sandbox = await client.notebook.get(sandboxId);

Call ready() when the next step requires the sandbox to be fully initialized, such as opening its preview:

TypeScript
const ready = await sandbox.ready();
console.log(ready.data.previewUrl);

Runtime operations such as filesystem and command calls wait for initialization when necessary.

Fork a sandbox

Forking creates another sandbox from the current state:

TypeScript
const fork = await sandbox.fork();

Changes in the fork do not alter the source sandbox.

Stop and restart

TypeScript
await sandbox.stop();
await sandbox.restart();

Stopping releases the sandbox's active compute without deleting its files and configuration. Restarting starts its compute again.

Delete a sandbox

TypeScript
await sandbox.destroy();

destroy() permanently deletes the remote sandbox. Use it only when the sandbox and its retained work are no longer needed.

Loading templates

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