How do I set environment variables for a Python script?
Short answer
Keep secrets and settings out of your code and set them where the script runs, then read them with os.getenv("NAME"). Hardcoding a key in the file is the thing to avoid. On Snapdock you add them to an encrypted Secrets vault and they're injected at runtime — never written into the code or the logs.
Why it happens — and how to fix it.
Why not just hardcode the key?
A key pasted into the code leaks the moment you share or re-upload the file, and it ends up in logs. Environment variables keep it separate.
Read them the normal way
Your Python reads a value with os.getenv("STRIPE_KEY"). The name is the contract; the value lives outside the code.
In Snapdock
Add each key in the Secrets vault. It's injected at runtime, encrypted at rest, and never printed to logs — and the pre-flight offers to move a hardcoded key into the vault for you.
Run it on Snapdock — no card to start.
Deploy and run any workflow or automation 24/7 — no servers, no Docker, no YAML.