Use cases · Codex

Data analysis with Codex: queries, CSVs and structured results

Codex can write and run the SQL and Python behind an answer, check the numbers and explain them. The sandbox is the part to plan for: by default its commands can't reach the network, so a warehouse or API query needs network access turned on, while CSVs in the workspace work as they are. This page covers access, the rules for AGENTS.md and getting results back as JSON.

What Codex does for data analysis

  • Answers questions with SQL against a read-only role or replica, and shows the query with the answer.
  • Cleans and analyses CSV exports with Python, and draws the charts.
  • Writes a weekly metrics digest: what moved, by how much, and the likely reason.
  • Flags anomalies, such as a drop in sign-ups or a spike in errors, before someone has to notice.

Codex features for data analysis

FeatureWhat it doesHow to start
Database CLI or MCP serverQueries your database or warehouse with a read-only roleA CLI in the sandbox, or an MCP server in config.toml
Network accessLets commands reach a warehouse or API; off by defaultnetwork_access = true under [sandbox_workspace_write]
--output-schemaThe final answer as JSON that matches your schemacodex exec --output-schema schema.json -o result.json
Scheduled tasksA weekly digest from the ChatGPT desktop app or the webCreate it in Scheduled

How to set up Codex for data analysis

  1. Connect the tools

    Give Codex a read-only role, and turn on network access only if the data isn't in the workspace. CSV exports in the project folder need nothing extra.

    # ~/.codex/config.toml: let commands reach your warehouse
    [sandbox_workspace_write]
    network_access = true
  2. Write the rules in AGENTS.md

    Codex reads AGENTS.md before any work: ~/.codex/AGENTS.md, then the files from the repository root down to the folder it's working in. Put the job's rules there, or in a skill under .agents/skills/ if they're long. See the AGENTS.md guide.

    ## Data rules
    - Read-only: use the analytics role, never the app's database
      user. No INSERT, UPDATE, DELETE or schema changes.
    - Show the query or script behind every number.
    - Compare with the period before, and say when a change is
      within normal noise.
    - Don't export personal data; aggregate before you write
      anything down.
    - Weekly digest: the five numbers that matter, what moved, and
      one question worth asking next week.
  3. Run it without the interactive interface

    codex exec runs one task and exits. Progress goes to stderr and the final message to stdout; -o also writes it to a file and --json streams events. The sandbox is read-only unless you pass --sandbox workspace-write.

    # Last week's numbers as JSON that matches your schema
    codex exec --sandbox workspace-write --output-schema metrics.schema.json \
      -o metrics.json "Compute last week's sign-ups, activation and revenue vs the week before"
  4. Put it on a schedule

    Create a scheduled task in the ChatGPT desktop app or on the web (the CLI doesn't manage them), or run codex exec from cron. See how to make Codex proactive.

Source: Codex documentation

Limits and safety

  • Give it a read-only role. An agent with write access to the database can change it.
  • It can misread what a column means. Write a short data dictionary and check its first answers.
  • Large results cost context and usage. Query and aggregate before reading rows.
  • Codex sandboxes commands by default: writes stay in the workspace and the network is off. Keep danger-full-access for an isolated runner or container.

Claude Code or Codex for data analysis?

The rules carry over. Write them once in AGENTS.md and put @AGENTS.md in CLAUDE.md, and both agents read the same file.

Step by step for the other agent: data analysis with Claude Code.

Claude CodeCodex
Rules fileCLAUDE.mdAGENTS.md
Connect toolsclaude mcp addcodex mcp add or config.toml
Run without youclaude -pcodex exec
Schedule/schedule, desktop scheduled tasks, /loopScheduled tasks in the ChatGPT app, cron
Built in for data analysis--json-schema structured output--output-schema structured output
With Crewmark

Make data analysis someone's job

Commands run when someone remembers to run them. Crewmark turns your own Codex into an AI employee with a role, a goal in numbers, working hours and a heartbeat, so the work happens on schedule and shows up on a board.

  1. Start from the role

    The AI employee roles, with these rules in its brief.

  2. Put the work on its board

    Add the job as a recurring issue. The employee wakes on its heartbeat, does it and reports in a comment.

  3. Related

    The daily SEO report is a worked example of a recurring analytics job.

FAQ

Can Codex do data analysis?

Yes. It writes and runs SQL and Python, analyses CSVs and explains what changed. Keep its database access read-only.

Why can't Codex connect to my database?

Commands in the default workspace-write sandbox have no network access. Turn it on in config.toml, or work from exported files in the workspace.

How do I get JSON results from Codex?

Pass --output-schema with a JSON Schema to codex exec, and add -o to write the final answer to a file.

Checked against Claude Code's and OpenAI's Codex documentation on November 13, 2026.

Hand data analysis to an AI employee on Codex.

Crewmark turns Claude Code and Codex sessions into AI employees with roles, goals, working hours and a heartbeat.