> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stackshift.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# Temporary PostgreSQL, MySQL, and Redis services

> Create, inspect, sleep, resume, snapshot, and delete managed sandbox database sidecars.

Temporary services are first-class sandbox resources backed by dedicated encrypted `sidecar` volumes. StackShift currently supports PostgreSQL, MySQL, and Redis. Each service has its own desired state, observed state, durable operation, runtime identity, resource limits, safe connection metadata, and failure details.

<Warning>
  Services are temporary dependencies, not production databases. Deployment handoff excludes their data and credentials.
</Warning>

## Create a service

The sandbox must exist and its capability policy must allow the engine and capacity. Names are DNS-safe lowercase identifiers; capacity is between the account/platform minimum and maximum.

```bash theme={null}
stackshift --timeout 10m --output json sandbox services create <sandbox-id> \
  --name app-db \
  --engine postgres \
  --capacity-gib 10 \
  --wait
```

Equivalent engine values are `mysql` and `redis`. Creation allocates the service resource and encrypted sidecar volume, then returns a mutation containing both the service and its operation.

List or inspect services without exposing credentials:

```bash theme={null}
stackshift sandbox services list <sandbox-id>
stackshift --output json sandbox services get <sandbox-id> <service-id>
```

## Connect from the sandbox

`connection_metadata` contains only safe fields: host, port, database, username, the environment key (`DATABASE_URL`, `MYSQL_URL`, or `REDIS_URL`), and credential delivery mode. The generated connection URL is written to the sandbox's volatile sidecar environment file and is not returned by list/get APIs or rendered in the dashboard.

Read the environment from a newly started execution rather than copying a credential into source:

```bash theme={null}
stackshift sandbox exec <sandbox-id> -- sh -lc 'test -n "$DATABASE_URL" && npm run migrate'
```

The explicit shell is required because `$DATABASE_URL` expansion is shell behavior. Do not print the variable, include it in errors, or write it to `.env`. Existing processes do not automatically gain newly created or rotated service credentials; restart them.

## Lifecycle

Service states are `queued`, `provisioning`, `starting`, `ready`, `sleeping`, `stopping`, `deleting`, `deleted`, or `failed`. `desired_state` is separate and may be `running`, `sleeping`, or `deleted`.

```bash theme={null}
stackshift --timeout 5m sandbox services sleep <sandbox-id> <service-id> --wait
stackshift --timeout 5m sandbox services start <sandbox-id> <service-id> --wait
```

Starting is idempotent when the service is already converging to or in the requested state. If an operation fails, inspect both its failure and the service's `failure_code`/`failure_message`; do not create a duplicate service to hide an unresolved failure.

## Snapshot database state

Use a `group` snapshot when the sandbox workspace and declared sidecars must form one recovery point:

```bash theme={null}
stackshift --timeout 15m sandbox snapshots create <sandbox-id> \
  --name before-schema-change \
  --type group \
  --retention-seconds 604800 \
  --wait
```

The platform quiesces the workload, snapshots the workspace and sidecar members, records the quiesce result and member checksums, and resumes the workload. Check that the snapshot reaches `ready` before relying on it. Snapshot manifests exclude volatile service credentials; restored services receive fresh credential material.

Restore replaces data in a sleeping target. Keep the default safety snapshot unless you have a deliberate reason not to:

```bash theme={null}
stackshift sandbox sleep <target-sandbox-id> --wait
stackshift --timeout 15m sandbox snapshots restore \
  <snapshot-id> <target-sandbox-id> \
  --safety-snapshot \
  --wait
```

## Delete a service

Deletion permanently removes the service and its owned sidecar volume. Snapshot or export required data, inspect the service ID, then confirm explicitly:

```bash theme={null}
stackshift --yes --timeout 10m sandbox services delete \
  <sandbox-id> <service-id> --wait
```

Deleting a sandbox also revokes service access and schedules owned resources for cleanup. An independently retained snapshot is not deleted merely because its source sandbox is destroyed.

<CardGroup cols={2}>
  <Card title="Security and persistence" href="/ai-sandboxes/security-lifecycle-and-limits">Understand encryption, sleep, snapshots, and deletion.</Card>
  <Card title="Troubleshooting" href="/ai-sandboxes/troubleshooting">Resolve readiness, capacity, snapshot, and recovery failures.</Card>
</CardGroup>
