# Publish a sandbox

Publishing deploys the product that is running in a sandbox and gives it a deployment URL. Unlike a preview, the published product does not depend on the sandbox's development environment remaining active.

Before publishing, verify the product through its preview and provide the production secrets and commands it needs to start without manual intervention.

## Publish with Cloudflare Containers

Link a Cloudflare integration and attach it to the sandbox:

```ts
const cloudflare = await client.integrations.link({
  provider: 'cloudflare',
  authorization: {
    type: 'token',
    token: process.env.CLOUDFLARE_API_TOKEN!,
  },
});

await sandbox.integrations.attach({ integration: cloudflare });
```

Then start the publication:

```ts
const run = await sandbox.publish({
  slug: 'inventory',
  provider: {
    name: 'cloudflare-containers',
    accountId: process.env.CLOUDFLARE_ACCOUNT_ID!,
    size: 'small',
  },
});

for await (const event of run.events()) {
  console.log(event);
}

const result = await run.result();
console.log(result.url);
```

Publishing is asynchronous. The event stream reports build and deployment progress, while `result()` resolves with the final status and URL.

## Other providers

PHPSandbox also supports Laravel Cloud and registered SSH servers. Their provider configuration is passed to the same `sandbox.publish()` method:

```ts
const run = await sandbox.publish({
  slug: 'inventory',
  provider: {
    name: 'laravel-cloud',
    region: 'eu-central-1',
  },
});
```

Laravel Cloud requires an attached Laravel Cloud integration and access to the product's provider repository. An SSH publication requires a registered server and uses its `serverId`.

## Publish again

Retrieve the sandbox's publication and publish its current state again:

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

if (publication) {
  const run = await publication.publish();
  console.log((await run.result()).url);
}
```

Publishing again keeps the publication configuration and creates a new build from the sandbox's current product state.
