Safe Secret Handling for Coding Agents
This post explains the secure handling of secrets (API keys, credentials, tokens) when working with coding agents—tools like GitHub Copilot, Codex, or Cursor. I'll cover why traditional ways of managing secrets aren’t safe when working with these agents, the potential security risks involved, and how we’ve approached solving this using Model Context Protocol (MCP) integrated with Delinea Secret Server. This isn't a deep dive into security theory, but rather a practical guide to addressing a real-world problem that many developers face today.
Recently, I’ve been using more coding assistants like Copilot and Codex to streamline my development workflows. These tools are great for automating repetitive tasks, debugging production code, or running integration tests. But here’s the issue—many of these tasks require access to sensitive information (API keys, database credentials, etc.). I quickly noticed that there isn’t a secure way for these coding agents to access secrets without risking leakage through chat logs, shell histories, or saved files.
I’m writing this post because I couldn’t find any public clear, practical advice on safely integrating secrets with coding agents, nor an easy-to-follow explanation on this topic. So here’s what I’ve come up with.
The common scenarios where agents need secrets include:
Today, developers typically paste secrets directly into the chat interface or keep them in files that agents can read. However, this introduces multiple security issues:
Clearly, we need a better approach.
Commonly used approaches include:
These methods lack proper audit trails, automatic rotation, and the dynamic control needed in modern workflows involving coding agents.
We’ve built a bridge called MCP—Model Context Protocol—that allows coding agents to securely fetch secrets from Secret Server – the vaulting capability on the Delinea Platform – avoiding any persistent traces.
Here’s how it works at a high level:
Here's a practical breakdown of the process:
Step 1: Agent requests secret
get_secret_environment_variable("db/prod", "bash")
Step 2: MCP authentication
MCP uses the developer’s existing SSO/MFA to authenticate the request and returns an ephemeral session key.
Step 3: Script generation
MCP generates a shell script containing the ephemeral key. Here’s an illustrative approximation of how the generated command looks:
# Approximation—not actual generated command
export DB_PASS=$(curl -s "https://mcp/api/secret/db/prod" \
- - header "Authorization: Bearer <ephemeral-session-key>" | jq -r
'.password')
(Note: The actual command securely generated by MCP may differ in format, but this captures the essence.)
Step 4: Secret fetch at runtime
When the agent runs the command, the secret is fetched directly into an environment variable. The only temporary log entry is the short-lived session key, never the secret itself.
Step 5: Cleanup
Once done, the agent runs the provided command to clear the secret from memory immediately:
unset DB_PASS
Using MCP + Secret Server offers:
Integrating coding agents into our workflow is powerful, but handling sensitive credentials carelessly can expose us to significant risk. By using MCP and Secret Server on the Delinea Platform, we’ve created a practical solution that allows agents to safely fetch secrets without compromising security. This approach keeps auditors happy, ensures compliance, and significantly reduces the risk surface.
The complete implementation and more detailed documentation are available on GitHub. If you have suggestions, improvements, or questions, please feel free to open a pull request or reach out directly.
Let me know your thoughts or questions—you can find me @gal_diskin on Twitter or @D1skin (and also @Disk1n) on GitHub.