C.W.K.
Stream
Lesson 09 of 11 · published

codex exec 로 스크립팅

~14 min · codex, exec, scripting, automation

Level 0🌱 입문자
0 XP0/70 lessons0/11 achievements
0/120 XP to next level120 XP to go0% complete

codex exec — Codex 의 print 모드

codex exec 가 non-interactive entry point. Prompt in (arg 또는 stdin), output stdout, exit. 모든 CLI 가 ship 하는 같은 모드, 다른 이름; Codex 에선 exec.

Output flag: --output-last-message (최종 답만, pipe 에 ideal), --output-format text|json|markdown. 도구 제약: Codex 가 active sandbox + approval mode 상속 → CI invocation 이 둘 다 --sandbox--ask-for-approval 로 핀.

Code

Three real exec patterns·bash
# 1. Generate a commit message from staged diff
git diff --staged | codex exec \
  --ask-for-approval never --sandbox read-only \
  "Write a concise conventional-commit message" \
  --output-last-message

# 2. Triage failing tests
npm test 2>&1 | tail -100 | codex exec \
  --sandbox read-only \
  "Diagnose these failures and rank by likely root cause" \
  > triage.md

# 3. Generate OpenAPI from route handlers
cat src/routes/*.ts | codex exec \
  --sandbox read-only \
  "Generate OpenAPI 3.1 spec for these handlers" \
  > openapi.yaml
Cron job example·bash
# crontab -e
30 22 * * 1-5 cd /workspace && /usr/bin/env codex exec \
  --ask-for-approval never \
  --sandbox workspace-write \
  "Update dependencies, run tests, write a one-paragraph
   summary to /workspace/nightly-summary-$(date +%F).md" \
  --output-last-message \
  >> /var/log/codex-nightly.log 2>&1

External links

Exercise

수동 run 하던 셸 스크립트 1개를 codex exec invocation 으로 교체. sandbox + approval 명시적 핀. cron 에 schedule. 1주일 후 로그 audit 으로 깨끗하게 run 했는지 verify.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.