Run SQL queries, check Redis memory, and inspect databases — all through exec
The exec endpoint isn’t just for running echo hello. Agents use it to interact with databases, caches, and any CLI tool running inside a container — turning natural language into actual application-level operations.
An agent asked “what’s the largest table in my Postgres?” runs psql inside the container:
Copy
async () => { const clusterId = "cls_abc123"; // resolved by the agent from conversation const res = await cnap.request({ method: "POST", path: `/v1/clusters/${clusterId}/exec`, body: { namespace: "default", pod: "postgres-0", container: "postgresql", command: ["psql", "-U", "postgres", "-c", ` SELECT schemaname, tablename, pg_size_pretty(pg_total_relation_size(schemaname || '.' || tablename)) AS total_size, pg_size_pretty(pg_relation_size(schemaname || '.' || tablename)) AS data_size, pg_size_pretty(pg_indexes_size(schemaname || '.' || quote_ident(tablename))) AS index_size, n_live_tup AS row_count FROM pg_stat_user_tables ORDER BY pg_total_relation_size(schemaname || '.' || tablename) DESC LIMIT 15; `] } }); return res.body;}
The agent gets back formatted SQL output with table sizes, index sizes, and row counts. It can then reason about which tables need vacuuming, which indexes are bloated, or whether a migration is needed.
Database operations through traditional MCP tools would need a dedicated tool per database type — postgres-query, redis-info, mongo-stats — each with their own schema, parameters, and maintenance burden.With exec + Code Mode, the agent writes the exact command it needs. It knows psql flags, redis-cli subcommands, and mongosh syntax from its training data. No pre-built tools required — the agent composes the right command for any database, any query.
Exec is non-interactive with a 30-second timeout. It’s ideal for read queries and diagnostics. For long-running operations or interactive sessions, use the dashboard terminal.