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

# Postgres sandbox CLI

> Give the Sazabi agent the Postgres client (psql) in its sandbox to query and inspect your PostgreSQL database.

[All Postgres integration capabilities](https://docs.sazabi.com/catalogs/integrations/postgres)

## About

This CLI connection makes the Postgres client (`psql`) available in the Sazabi agent's sandbox. The agent can use it to query your Postgres database. The tool is baked into the sandbox image; connecting it configures the connection for the already-installed CLI.

## Prerequisites

* A Sazabi project.
* PostgreSQL connection details:
  * `PGHOST` — hostname or IP address of your PostgreSQL server.
  * `PGPORT` — port your PostgreSQL server listens on (typically `5432`).
  * `PGUSER` — PostgreSQL username.
  * `PGPASSWORD` — PostgreSQL password for the specified user.
* Optionally:
  * `PGDATABASE` — default database name to connect to.
  * `PGSSLMODE` — SSL mode (e.g., `require`, `verify-full`).
  * `PGCONNECT_TIMEOUT` — connection timeout in seconds.
  * `PGTZ` — timezone for the session.
  * `PGOPTIONS` — additional server options.
  * `PGREADONLY` — set to `on` to enforce a read-only session.

## Set up in the dashboard

Configure the sandbox in the dashboard under [**Settings > Sandbox CLIs**](https://app.sazabi.com/settings/sandbox-clis).

**Step 1**

### Find Postgres in the catalog

In [**Settings > Sandbox CLIs**](https://app.sazabi.com/settings/sandbox-clis), find Postgres under **Browse sandbox CLIs** and choose to connect it.

**Step 2**

### Provide credentials

Enter the required values: `PGHOST` — your PostgreSQL server hostname; `PGPORT` — the port (typically `5432`); `PGUSER` — your PostgreSQL username; `PGPASSWORD` — your PostgreSQL password. Optionally, provide `PGDATABASE`, `PGSSLMODE`, `PGCONNECT_TIMEOUT`, `PGTZ`, `PGOPTIONS`, and/or `PGREADONLY` to further configure the connection. Save to store them securely; Sazabi injects them into the sandbox when the agent runs.

## Set up with the CLI

You can also configure the Postgres CLI connection with the [Sazabi CLI](https://docs.sazabi.com/reference/cli.md) (installed and authenticated — see [CLI reference](https://docs.sazabi.com/reference/cli/sandbox-clis.md)).

```bash theme={"system"}
sazabi sandbox-clis connect postgres --env PGHOST=<your-host> --env PGPORT=5432 --env PGUSER=<your-user> --env PGPASSWORD=<your-password>
```

To validate the credentials without saving, run the same command with `test` in place of `connect` (the test command also requires the `--env` flags).

## Verify

Ask the agent, in a thread, to run the `psql` CLI (a read-only or status command) and confirm it returns real output. If the command is not found, the CLI connection may not be enabled; if it runs unauthenticated or cannot connect, recheck the credentials.

## Troubleshooting

**Command not found** — Confirm the Postgres CLI connection is enabled for the project under [**Settings > Sandbox CLIs**](https://app.sazabi.com/settings/sandbox-clis).

**Authentication or connection fails** — Recheck the credential/connection values under [**Settings > Sandbox CLIs**](https://app.sazabi.com/settings/sandbox-clis).

## Further reading

> [card] [Working with the agent](https://docs.sazabi.com/ask/better-answers.md)
>
> Put the connected CLI to work in an investigation thread.

> [card] [Set up the sandbox](https://docs.sazabi.com/ask/sandbox.md)
>
> How the sandbox works and its security model.

> [card] [Sandbox CLIs](https://docs.sazabi.com/catalogs/integrations.md#sandbox-clis)
>
> Browse the catalog and connect more tools.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.