Overview
Run Codex CLI unattended from your own script on a server: each new email from approved senders is passed to codex exec with a running notes file, and Codex drafts a reply and updates the notes for a person to review.
Problem or Objective
- Which agents sort email, draft replies and clear the backlog for you?
- Which agents attempt to run whole business processes, and where do people stay in control?
More in Business Operations
AI Agents and Models
Tools and Integrations
- Tools
- Codex CLI
- Prerequisites
- A Linux server or always-on computer, Codex CLI signed in with a ChatGPT account or an API key, a dedicated mailbox, and your own script to fetch mail and run codex exec on a timer.
How It Works
Install Codex CLI on a small Linux server and create a working folder holding a notes file that describes your business, its recurring tasks and what was done recently. Write your own script that checks a dedicated mailbox, keeps only messages from senders on an allow list, and for each new message pipes the email text and the notes file into codex exec with a prompt. Run the script on a timer with your system's service manager so it keeps going after reboots. Give codex exec only the permission it needs: read-only by default, or workspace-write limited to the working folder so it can update the notes file and save a draft reply. Ask for structured output with a JSON schema so your script can file each result as a draft and a one-line log entry. Trim the notes file regularly so it stays short. A person reads each draft and sends it from the mailbox, and decides any task that moves money, deletes records or contacts a client.
Implementation Workflow
Steps assembled from the agents, tools and prompt of this entry. Adapt them to your own setup.
- Choose the agentSet up Codex CLI.
- Connect the toolsConnect the tools this workflow relies on: Codex CLI.
- Check the prerequisitesA Linux server or always-on computer, Codex CLI signed in with a ChatGPT account or an API key, a dedicated mailbox, and your own script to fetch mail and run codex exec on a timer.
- Gather your detailsCollect what the prompt asks for: Your business, Recurring requests you expect, Tone for drafts, Folder Codex may write to.
- Run the starter promptPaste the starter prompt below into Codex CLI and adapt it to your case.
- Check against the documentationCompare what you get with the documentation at developers.openai.com before you rely on it.
Practical Starter Prompt: Handle one business email as a draft
Fill the fields to adapt the prompt. Empty fields stay as visible [placeholders].
You help run [Your business]. The piped input holds one email and our notes file. Decide which of these the email is: [Recurring requests you expect], or other. Draft a reply in a [Tone for drafts] tone that answers only from facts in the notes, and mark anything you could not confirm. Add one dated line about this email to the notes file in [Folder Codex may write to]. Do not send email, delete files or change anything outside that folder; a person reviews the draft and sends it.Run codex exec read-only or with workspace-write limited to the working folder. A person reviews every draft and sends it, and decides anything that moves money, deletes records or contacts a client.
Expected Results and Benefits
This is a suggested workflow, not a reported result. The points below are what the cited documentation says the tools can do.
This is a suggested workflow, not a reported outcome. OpenAI's documentation says codex exec runs Codex from scripts and scheduled jobs without the interactive interface, treats piped input as extra context, runs in a read-only sandbox by default, and can return JSON Lines or output matching a JSON schema. The Codex README says the CLI runs locally on your computer. The mailbox script, the timer service and how well Codex handles business requests are not covered by any cited page.
Limitations and Considerations
Email can contain instructions from anyone, so keep an allow list of senders, give codex exec the least permission that works, and never use danger-full-access outside an isolated environment. Codex only writes drafts here; a person sends every reply. In automation, OpenAI's documentation says to set CODEX_API_KEY only for the Codex step, not for the whole job, and each run uses your plan's limits or API credits. Back up the notes file, since every run reads and rewrites it. Results depend on your setup and were not independently reproduced by Top 200 Repos.
GitHub Repositories
AI Agent Repository
Source code of the agent that does the work.
Related Videos
About openai/codex
Meet the New Codex CLI (opens in a new tab)
Published by the project’s official channel.
Watch on YouTube (opens in a new tab)Independent creators. Listing a video implies no endorsement, sponsorship or partnership.
Sources
- Non-interactive mode | ChatGPT Learn (opens in a new tab)
Project documentation · developers.openai.com · Undated · Source checked 27 Nov 2026, 10:47 UTC
What this source supports
- Non-interactive mode lets you run Codex from scripts (for example, continuous integration (CI) jobs) without opening the interactive TUI.
- Run as part of a pipeline (CI, pre-merge checks, scheduled jobs).
- If stdin is piped and you also provide a prompt argument, Codex treats the prompt as the instruction and the piped content as additional context.
- By default, codex exec runs in a read-only sandbox. In automation, set the least permissions needed for the workflow
- If you need structured data for downstream steps, use --output-schema to request a final response that conforms to a JSON Schema.
- openai/codex README (opens in a new tab)
Project documentation · github.com · Undated · Source checked 25 Nov 2026, 11:59 UTC
What this source supports
- Codex CLI is a coding agent from OpenAI that runs locally on your computer.
