env-isolation-pattern

Isolate production environment variables from pytest and alembic subprocesses.

Updated Apr 4, 2026
One-click install
npx skills add https://github.com/saintgo7/claude-skills --skill env-isolation-pattern
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: env-isolation-pattern
Source: https://github.com/saintgo7/claude-skills/tree/main/env-isolation-pattern
Command: npx skills add https://github.com/saintgo7/claude-skills --skill env-isolation-pattern

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill prevents production environment variables from being inherited by tests and migrations, which can accidentally connect to (and wipe) the production database.

Core Features & Use Cases

  • Production-to-Test Environment Isolation: removes or overrides prod-like variables before subprocesses (pytest, alembic, migration scripts) run.
  • Strong Guardrails Beyond setdefault: replaces weak os.environ.setdefault(...) with explicit unsetting and unconditional overrides at import time.
  • Practical Deployment Scenarios: supports local wrappers, CI/CD pipelines, supervisor/export flows, and container-based isolation to eliminate the most common leak paths.

Quick Start

Tell the Skill to generate a safe test runner and conftest isolation snippet that unsets all prod-prefixed environment variables and forces test-only DB and secret values for your stack.

Frequently Asked Questions about env-isolation-pattern

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent pytest integration tests from accidentally connecting to and wiping a production database?

Prevent pytest database wipes by enforcing environment isolation that unsets production-prefixed variables and overrides DB connection strings at import time. This ensures destructive integration tests only run against test-only databases and fail-fast if prod secrets leak.

Why does os.environ.setdefault not prevent environment variable leaks in alembic migrations?

Using os.environ.setdefault for environment isolation fails because it only sets missing variables and cannot override existing prod-like variables exported by parent shells. Replacing weak setdefault with explicit unsetting and unconditional overrides prevents alembic upgrades from inheriting prod connectivity.

How do I stop CI pipelines from leaking production secrets into migration subprocesses?

Stop CI secret leaks by applying explicit unset/override isolation patterns before migration subprocesses execute. Force unconditional test-only DB and secret values at top-level conftest execution, preventing parent shell exports from passing production environment variables downstream.

Does environment isolation work with container-based deployment and supervisor export flows?

Yes, environment isolation supports container-based isolation, local wrappers, CI/CD pipelines, and supervisor/export flows. It eliminates common leak paths by removing prod-like variables before subprocesses run, ensuring destructive tests and migrations fail to connect to production databases.

What is the best way to validate fail-fast leak prevention for secret-prefix environment variables?

The best fail-fast leak validation checks for secret-prefix environment variables at top-level conftest execution before subprocesses run. Explicitly unset and override these variables to guarantee test runners and migration scripts abort immediately if production environment variables are detected.