Logs are where an AI coding assistant is most useful in production: it can read a stack trace, find the matching code and propose a fix. Giving it SSH so it can run docker logs is far more access than it needs. A read only path to logs gets most of the benefit with little of the risk.
What the agent actually needs#
- Recent logs for a named app, filtered by time and level.
- Maybe container status: running, restarting, exit code.
It does not need to run commands, read environment variables, or open a terminal.
Option 1: export logs to a tool it can query#
If logs already go to Loki, Elasticsearch or a hosted log service, create a read only API token scoped to the relevant streams. Give the agent that token through its tool configuration. The worst a leaked token can do is read logs.
Option 2: a narrow MCP tool#
An MCP server exposing a single get_logs(app, since, level) tool is a few dozen lines. Internally it calls the Docker API or your platform's API with a service account that can only read logs. Keep a fixed allowlist of apps and cap the number of lines returned.
Option 3: platform roles#
If your deployment platform has roles, create a viewer role for the agent's token. Many platforms separate viewing logs from opening a terminal, which is exactly the line you want.
Scrub secrets before the agent sees them#
Logs leak more than people expect: connection strings in error messages, tokens in request URLs, email addresses. Add a redaction step for common patterns before logs reach the agent, and fix the application code that prints secrets.
Keep an audit trail#
Record which tool calls the agent made and when. If something odd happens, you want to know what it looked at.
What to keep for humans#
Restarting services, running migrations and opening a terminal should stay with people, or at minimum require an explicit human approval step.
Peon's documentation on logs and terminal access in Peon shows how log viewing and terminal access are handled per app.
Disclosure: I help build Peon (https://peon.sh/), a deployment platform with role based access for people and agents.
Comments
No comments yet. Start the conversation.