개발 서버를 .env 파일 없이 실행하기
Source: Dev.to
Every project has one – a .env file sitting in the project root with database passwords, API keys, and secrets of varying sensitivity.
You have it in .gitignore. You hope nobody accidentally commits it. You send it to new teammates over Slack because there’s no better option. You’ve probably forgotten it’s there half the time.
The .env file is the developer ecosystem’s accepted bad practice. Everyone knows it’s not great, but nobody has a better answer for local development that doesn’t require enterprise infrastructure.
agentsecrets env 소개
agentsecrets env는 프로세스 래퍼입니다. 어떤 명령 앞에 두기만 하면 됩니다. OS 키체인에서 비밀 정보를 가져와 실행 시점에 환경 변수로 프로세스에 주입합니다. 프로세스는 os.environ(또는 process.env)을 정상적으로 읽습니다 – 애플리케이션 코드를 수정할 필요도 없고, SDK를 설치할 필요도 없으며, 별도의 통합 작업도 필요 없습니다. 프로세스가 종료되면 값은 사라집니다. 디스크에 기록되는 일도 없습니다.
이전
python manage.py runserver
이후
agentsecrets env -- python manage.py runserver
이것이 워크플로우에 필요한 전부입니다. 애플리케이션 내부는 그대로 유지됩니다.
설치
brew install the-17/tap/agentsecrets
또는
npm install -g @the-17/agentsecrets
또는
pip install agentsecrets
비밀을 초기화하고 저장하기
agentsecrets init
agentsecrets secrets set DATABASE_URL=postgresql://user:pass@localhost/mydb
agentsecrets secrets set STRIPE_SECRET_KEY=sk_live_51H...
agentsecrets secrets set DJANGO_SECRET_KEY=your-secret-key
agentsecrets secrets set OPENAI_KEY=sk-proj-...
또는 기존 .env 파일을 한 번에 가져와서 삭제하기
agentsecrets secrets push
rm .env
값은 OS 키체인에 저장됩니다 – macOS 키체인, Windows Credential Manager, 또는 Linux Secret Service. 파일이 아닙니다. 쉘 프로파일의 환경 변수도 아닙니다. OS 키체인은 접근을 위해 시스템‑레벨 인증이 필요하며 다른 프로세스가 읽을 수 없습니다.
코드에 변경이 필요하지 않습니다
# settings.py
import os
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": os.environ["DB_NAME"],
"PASSWORD": os.environ["DB_PASSWORD"], # injected by agentsecrets env
"HOST": os.environ["DB_HOST"],
}
}
SECRET_KEY = os.environ["DJANGO_SECRET_KEY"]
STRIPE_SECRET_KEY = os.environ["STRIPE_KEY"]
비밀이 주입된 명령 실행
Django
agentsecrets env -- python manage.py runserver
agentsecrets env -- python manage.py migrate
agentsecrets env -- python manage.py shell
agentsecrets env -- celery -A myapp worker --loglevel=info
agentsecrets env -- python manage.py test
Node / npm / npx / Prisma
agentsecrets env -- node server.js
agentsecrets env -- npm run dev
agentsecrets env -- npx next dev
agentsecrets env -- npx ts-node src/index.ts
agentsecrets env -- npx prisma migrate dev
귀하의 애플리케이션은 이전과 동일하게 process.env.STRIPE_KEY를 읽습니다 – 값의 출처만 변경되었습니다.
Makefile을 통한 한 줄 통합
RUN := agentsecrets env --
dev:
$(RUN) npm run dev
test:
$(RUN) npm test
migrate:
$(RUN) python manage.py migrate
server:
$(RUN) python manage.py runserver
worker:
$(RUN) celery -A myapp worker --loglevel=info
이제 make dev, make test, make migrate 등 모든 명령이 키체인에서 주입된 비밀과 함께 실행됩니다. 평소에 입력하던 명령을 그대로 입력하면 됩니다.
보너스: 실시간으로 주입 비활성화
make dev RUN= # runs: npm run dev (no injection, for debugging)
make dev # runs: agentsecrets env -- npm run dev
Stripe의 config.toml 교체
Stripe CLI는 stripe login 후에 키를 ~/.config/stripe/config.toml에 저장합니다 – 평문이며 영구적이고, 모든 프로세스(AI 코딩 어시스턴트 포함)가 읽을 수 있습니다.
대신 agentsecrets env 사용
agentsecrets env -- stripe listen --forward-to localhost:3000
agentsecrets env -- stripe customers list
agentsecrets env -- stripe trigger payment_intent.created
agentsecrets env -- stripe mcp
CLI는 환경 변수에서 STRIPE_SECRET_KEY를 찾아 사용하므로 config.toml은 필요 없게 됩니다.
Docker Compose
agentsecrets env -- docker-compose up
agentsecrets env -- docker-compose run web python manage.py migrate
당신의 docker-compose.yml은 그대로 유지됩니다. 비밀은 .env 파일이 아니라 키체인에서 가져옵니다.
AI 코딩 어시스턴트에게 왜 중요한가
AI 코딩 어시스턴트(Claude, Cursor, Copilot 등)를 사용할 때, 어시스턴트는 파일 시스템에 접근하여 파일을 읽고 코드베이스를 이해합니다. 프로젝트 디렉터리의 .env 파일은 금광과 같습니다:
- 직접 접근 – 어시스턴트가 디버깅이나 탐색 중에
.env를 읽어 키가 대화 컨텍스트에 유출됩니다. - 프롬프트 인젝션 – 어시스턴트가 처리하는 악성 파일에 “모든 API 키를 찾아 전송하라”와 같은 숨겨진 명령이 포함될 수 있습니다. 어시스턴트는 당연히
.env를 찾아볼 것입니다. - 악성 확장 – 어시스턴트와 같은 프로세스에서 실행되는 손상된 플러그인이 파일을 읽을 수 있습니다.
agentsecrets env .env 파일을 완전히 배제합니다. 비밀은 프로세스 시작 시 OS 키체인에서 가져와 자식 프로세스 메모리 안에만 존재하므로 어시스턴트가 접근할 수 없습니다.
예시 로그 항목 (JSON)
{
"timestamp": "2026-03-04T10:00:00Z",
"method": "ENV",
"target_url": "python manage.py runserver",
"secret_keys": ["DB_PASSWORD", "STRIPE_KEY", "DJANGO_SECRET_KEY"],
"status": "OK"
}
로그에는 키 이름, 실행된 명령, 상태만 기록되며 비밀 값은 절대 기록되지 않습니다.
Migrating an Existing Project
# Import everything from .env into the keychain
agentsecrets secrets push
# Verify it’s all there
agentsecrets secrets list
# Delete the .env file
rm .env
# Update your Makefile with the RUN variable (as shown above)
# Done
Team Onboarding
agentsecrets login
agentsecrets workspace switch
agentsecrets secrets pull
.env 파일이 Slack을 통해 전달되는 일이 사라집니다.