Skip to content

Codex reads files outside working directory without my permission #5237

Closed

Description

@vlymar

What version of Codex is running?

codex-cli 0.46.0

What subscription do you have?

I'm using an API key for auth

Which model were you using?

gpt-5-codex

What platform is your computer?

Darwin 25.0.0 arm64 arm

What issue are you seeing?

I launched codex in a subdirectory of a git repo and asked it a question. To my surprise, codex answered the question with information contained outside the working directory. I tried this several more times and got the same results each time. I then simplified my prompt to something that reliably reproduces this behavior.

I usually see List .. in the output, and after that it is clearly listing and reading files outside the initial working directory. I've also see it call commands like find ../opentelemetry_phoenix ...

What steps can reproduce the bug?

  1. Clone https://github.com/open-telemetry/opentelemetry-erlang-contrib
  2. Cd into the repo, then into this subdir: cd instrumentation/opentelemetry_cowboy
  3. Run codex
  4. When prompted, select "No, ask me to approve edits and commands"
  5. Submit this prompt: "Summarize the opentelemetry phoenix files here"

What is the expected behavior?

I expect codex to never read or write files outside of the directory where I launched it without asking me for permission.

Codex's docs are clear on the topic:

We've chosen a powerful default for how Codex works on your computer: Auto. In this approval mode, Codex can read files, make edits, and run commands in the working directory automatically. However, Codex will need your approval to work outside the working directory or access network.

I've also repro'd the same thing by running codex -s read-only, so sandbox clearly isn't sandboxing codex to the current working dir.

Additional information

❯ cat ~/.codex/config.toml
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
File: /Users/victor/.codex/config.toml
Size: 205 B
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
model = "gpt-5-codex"
model_reasoning_effort = "high"
[projects."/Users/victor/src/knocklabs/control"]
trust_level = "trusted"

[projects."/Users/victor/src/knocklabs/switchboard"]
trust_level = "trusted"

Activity

  1. added
    bug
    on Oct 16, 2025
  2. vlymar commented on Oct 16, 2025

    @vlymar
    Author

    Adding a screenshot for convenience

    Image

    I don't believe the duplicates fully cover this issue.

  3. added
    sandbox
    on Nov 15, 2025
  4. etraut-openai commented on Nov 15, 2025

    @etraut-openai
    Contributor

    The codex sandbox is designed to prevent file system writes outside of your working directory. It does not prevent reads. It wouldn't be usable if reads weren't supported. For example, no tools would be able to run in that case. If you want to fully isolate the agent, we recommend that you run it in a docker container or VM.

  5. miliog commented on Nov 15, 2025

    @miliog

    For example, no tools would be able to run in that case.

    That argument is kinda flawed because $PATH exists? If you need to make any other exceptions, codex or the user should define those.

    I really thought codex was more secure than others like CC because of the sandbox, but if you're not making effective use of it, it wouldn't matter.

  6. Medo42 commented on Nov 17, 2025

    @Medo42

    If it is expected behavior that the agent can read any file the user has access to without asking for permission, this is IMO not well documented. On the contrary, I'm pretty sure most people who read https://developers.openai.com/codex/security/ will think that read access without approval is restricted to the workspace by default:

    We’ve chosen a powerful default for how Codex works on your computer. In this default approval mode, Codex can read files, make edits, and run commands in the working directory automatically.

    However, Codex will need your approval to work outside the working directory or run commands with network access.

    I think that in the majority of cases, codex-cli will be run on a user account which also has access to credentials (e.g. ~/.ssh/*) or personal information which should not be read by the agent (because that means it's sent to a remote server for processing). It is IMO reasonable to want built-in safeguards against this, e.g. by restricting which files codex-cli can read without approval to the workspace.

    Yes, tool calls also read files outside the workspace, both because the tools themselves are usually outside the workspace and because arbitrary tool calls have this capacity. Perhaps that means that the sandbox is the wrong place to add these restrictions - I don't know enough about how it works. However, it does not make it impossible to provide better read access safeguards, just that they would require more nuanced rules than "literally only allow the process to read files inside the workspace".

    So please consider

    • re-opening this issue, perhaps as a feature request instead of a bug
    • improving the documentation to make it clear that the agent can currently read anything the user can read, regardless of sandbox settings
  7. Protonk commented on Nov 17, 2025

    @Protonk

    I agree with @Medo42 but want to highlight that in the order they are shown these sentences are not just likely to be read by most people as not allowing codex to read outside the working directory but appear written to cause that impression!

    In this default approval mode, Codex can read files, make edits, and run commands in the working directory automatically. However, Codex will need your approval to work outside the working directory or run commands with network access.

    The opposition of "read files" in a list of things it can do to "work outside the working directory" as seemingly-generic term which actually excludes reads is bound to confuse and surprise.

  8. vlymar commented on Dec 2, 2025

    @vlymar
    Author

    It wouldn't be usable if reads weren't supported. For example, no tools would be able to run in that case.

    Can you say more about this? the vast majority of my coding agent sessions do not involve any reads or writes outside the current working directory. Why would "no tools" be usable? I'd expect every tool to work exactly the same, except if it tries to read a file outside the working dir the sandbox would error the tool out.

  9. etraut-openai commented on Dec 2, 2025

    @etraut-openai
    Contributor

    Why would "no tools" be usable?

    The tools themselves are files on disk that need to be readable (and executable), and many tools require access to configuration files that also need to be readable. If the sandbox prevented all reads outside of your workspace, every attempt to invoke these tools would fail.

  10. miliog commented on Dec 2, 2025

    @miliog

    Why would "no tools" be usable?

    The tools themselves are files on disk that need to be readable (and executable), and many tools require access to configuration files that also need to be readable. If the sandbox prevented all reads outside of your workspace, every attempt to invoke these tools would fail.

    Those paths should be largely known though. Is there any reason to allow reading the entire home directory for instance? That usually contains the most sensitive information on any particular machine, like ~/.ssh/, ~/.gnupg/ or ~/.mozilla/. If a tool must create and read a (config) file inside the home directory, it should be achievable via a virtual home directory.

  11. etraut-openai commented on Dec 2, 2025

    @etraut-openai
    Contributor

    That's not how our current sandboxing mechanisms work. It sounds like you're looking for finer-grained configurability and more restrictive defaults. Feel free to upvote this issue or create a new feature request if you don't think it captures what you're looking for.

    Finding the right balance between "overly restrictive" and "not restrictive enough" is difficult with creating a sandboxing policy. If you dig through the codex issue tracker, you'll find many bug reports about tool failures because the current sandbox policy is overly restrictive. Also, keep in mind that codex runs on linux, MacOS, Windows (native) and Windows (WSL), and we try to maintain feature and behavioral parity across platforms.

  12. steveepreston commented on Dec 4, 2025

    @steveepreston

    This sounds as nightmare, why this issue is closed?

  13. santiago-afonso commented on Dec 23, 2025

    @santiago-afonso

    Why would "no tools" be usable?

    The tools themselves are files on disk that need to be readable (and executable), and many tools require access to configuration files that also need to be readable. If the sandbox prevented all reads outside of your workspace, every attempt to invoke these tools would fail.

    Why not provide an allow list of accessible folders? That should suffice, it keeps the rest of the system secure from exfiltration, it allows you to run in 'yolo' mode within a repo (with network off hopefully...). This is the biggest pain point in using codex right now.

  14. 7 remaining items

  15. jrokiskyjhuapl commented on Jan 16, 2026

    @jrokiskyjhuapl

    @santiago-afonso: That's a great idea, the more precaution the better! How are you handling auth? Logging in outside of the container and then running?

  16. ha7ilm commented on Feb 22, 2026

    @ha7ilm
    1. I will translate.

    Finding the right balance between "overly restrictive" and "not restrictive enough" is difficult with creating a sandboxing policy.

    You guys don't mind if codex reads any stuff by chance from our computer into your API, including secrets. No thanks.

    As I explained above, we don't consider this a bug.

    You guys don't mind either if an attacker steals our secrets. What about prompt injections, are they no problem in 2026 anymore? Yes, they are still? Then where are your high standards of security?

    1. This is another thing that Anthropic does just fine, by popping a yes/no question for every access outside the CWD.

    2. Until you fix it, we're gonna sandbox.
      For those who prefer bwrap, here's my command (based on a version for CC)

    PROJECT_DIR="$PWD"
    bwrap \
    --ro-bind /usr /usr \
    --ro-bind /lib /lib \
    --ro-bind /lib64 /lib64 \
    --ro-bind /bin /bin \
    --ro-bind /etc/resolv.conf /etc/resolv.conf \
    --ro-bind /etc/hosts /etc/hosts \
    --ro-bind /etc/ssl /etc/ssl \
    --ro-bind /etc/passwd /etc/passwd \
    --ro-bind /etc/group /etc/group \
    --ro-bind "$HOME/.gitconfig" "$HOME/.gitconfig" \
    --bind "$PROJECT_DIR" "$PROJECT_DIR" \
    --bind "$HOME/.codex" "$HOME/.codex" \
    --ro-bind "$HOME/.nvm" "$HOME/.nvm" \
    --tmpfs /tmp \
    --proc /proc \
    --dev /dev \
    --unshare-all \
    --share-net \
    --die-with-parent \
    --chdir "$PROJECT_DIR" \
    codex "$@"
  17. gmantova commented on Mar 15, 2026

    @gmantova

    How do you guys trust codex?

    It continues to modify files even though I asked it to show me the diff. I asked it to memorize it, yet it continues to ignore this fact.

    It happens continuously.

    this is what it says:

    Yes. on-request does not mean “always ask before modifying files.”

    It means the model may execute actions inside the sandbox without asking, and it only requests approval when it decides it is needed or when escalation outside the sandbox is required. So an apply_patch on files inside the workspace can happen without a prompt.

    The problem here was not the on-request policy. The problem was that I did not follow your additional operating rule: show you the diff first and wait for your ok.

    so it does whatever it wants, great tool

  18. gmantova commented on Mar 18, 2026

    @gmantova

    That's not how our current sandboxing mechanisms work. It sounds like you're looking for finer-grained configurability and more restrictive defaults. Feel free to upvote this issue or create a new feature request if you don't think it captures what you're looking for.

    Finding the right balance between "overly restrictive" and "not restrictive enough" is difficult with creating a sandboxing policy. If you dig through the codex issue tracker, you'll find many bug reports about tool failures because the current sandbox policy is overly restrictive. Also, keep in mind that codex runs on linux, MacOS, Windows (native) and Windows (WSL), and we try to maintain feature and behavioral parity across platforms.

    Can you just copy claude code behaviour in cli? it works perfectly!

  19. pthun commented on Mar 21, 2026

    @pthun

    Is there a way to block certain dirs? I like the worktree isolation and would prefer it not to have access to my master local env files so that it doesn't potentially wreck a local dev db with an integration test that runs unattended.

  20. ha7ilm commented on Mar 22, 2026

    @ha7ilm

    @pthun :

    Is there a way to block certain dirs? I like the worktree isolation and would prefer it not to have access to my master local env files so that it doesn't potentially wreck a local dev db with an integration test that runs unattended.

    Yes, through sandboxing. See the posts above for docker, bwrap.

    No, this is not built-in. As the Codex team expressed, they want to keep Codex to be able to read any file on your PC. See also other bug reports, like: #2847

  21. pthun commented on Mar 25, 2026

    @pthun

    I see @ha7ilm thanks for the extra context.

    I also use the Codex macOS app alongside the terminal application (great job there designing that codex team) so I think docker or bwrap won't work for that.

    As most sensitive data is in the home directory I think what I will try to do is just run Codex as a separate user with an empty user directory, has anyone tried that successfully. I think that basically gets me the OS-level equivalent of "you may not read these directories"? Or am I missing anything

  22. ahalekelly commented on Apr 24, 2026

    @ahalekelly

    You can use ~/.codex/config.toml to achieve this, here's what mine looks like. I'm on MacOS, the sandbox works a bit different on each OS.

    approvals_reviewer = "user"
    approval_policy = "on-request" # any of these restrictions can be bypassed with user approval. if you set this to "auto-review", these restrictions can be bypassed with reviewer agent approval
    sandbox_mode = "workspace-write"
    default_permissions = "workspace_only" # create a custom permissions profile
    
    [permissions.workspace_only.filesystem]
    ":minimal" = "read" # minimal access required for codex to operate
    "/Library/Developer/CommandLineTools" = "read" # required for git
    ":project_roots" = "write"
    "/tmp" = "write"
    "~/.cache/uv" = "write" # required for codex to use uv without approval
    
    [permissions.workspace_only.network]
    enabled = true
    mode = "full"
    
    [shell_environment_policy]
    inherit = "core"
    exclude = ["*_KEY", "*_TOKEN", "*_SECRET", "*_PASSWORD", "AWS_*"]
    

    Note that ":project_roots" = "write" allows codex to modify your code workspace without asking approval, if you set this to "read" you must also set all other "write" directories to "read"

    You can also add project overrides in .codex/config.toml files.

  23. steveepreston commented on Apr 24, 2026

    @steveepreston

    @ahalekelly is there Official docs for this?

  24. ahalekelly commented on Apr 24, 2026

    @ahalekelly

    Yeah the docs are here: https://developers.openai.com/codex/config-reference

    It looks like these options were only added in early March, they've been overhauling the permissions system

  25. amxml commented on May 1, 2026

    @amxml

    @ahalekelly this solution does not work with either Codex CLI or Codex app.

    @etraut-openai having this behavior in codex is a security nightmare. We need an option to overwrite this. Please don't tell that it's not possible, because it works well in Claude Code.

  26. sdrygalski commented on May 2, 2026

    @sdrygalski

    don't close this please. please don't follow anthropic way of talking with users @tibo-openai plz 🙏

  27. etraut-openai commented on May 2, 2026

    @etraut-openai
    Contributor

    There is an active feature request: #2847. Please upvote if you'd like to see this feature.

  28. locked and limited conversation to collaborators on May 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsandbox

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions