What counts as a secret

Your weather agent needs two things it shouldn't print or share: an API key for the forecast service, and the key it uses to send email. If someone else gets them, they can use your account and run up your bill.

A good rule: if it would let a stranger act as you, it's a secret. Your city name isn't. Your OPENWEATHER_API_KEY is.

How keys leak

Most leaks aren't hacks. They happen when a key is typed straight into the code:

agent.py · don't do this
API_KEY = "sk_live_4f9a..."   # now in every copy of this file

Then the file gets pasted into a chat, pushed to GitHub, or zipped and sent to a friend, and the key goes with it.

Warning. If a key has ever been committed or shared, deleting it from the file isn't enough. Create a new key with the provider and revoke the old one.

Use a .env file

Put secrets in a file called .env next to your code, one per line:

.env
OPENWEATHER_API_KEY=your-key-here
[email protected]

Then tell git to ignore it, so it never ends up in your repository:

.gitignore
.env

Read it from Python

Your code asks for the value by name instead of containing it:

agent.py
import os
from dotenv import load_dotenv

load_dotenv()  # reads .env when you run locally
api_key = os.environ["OPENWEATHER_API_KEY"]
Tip. Ask your coding assistant: "Move any hard-coded keys in this project into .env and read them with os.environ." It's a quick, safe refactor.

On Thinkmon

When your assistant uploads your agent, the deployment instruction tells it to leave .env and credential files behind. Thinkmon then lists the names your code reads, such as OPENWEATHER_API_KEY, and you enter the values in the dashboard.

Saved values are never shown again on screen. Your code reads them exactly as it did locally, through os.environ.

Try it on Thinkmon

Host the agent you just cleaned up. It starts paused, so nothing runs until you check it.

Sign up