Skip to content

feat(interp): expose ALLOWED_PATHS environment variable#173

Merged
matt-dz merged 6 commits intomainfrom
matt-dz/allowed-paths-env-var
Apr 3, 2026
Merged

feat(interp): expose ALLOWED_PATHS environment variable#173
matt-dz merged 6 commits intomainfrom
matt-dz/allowed-paths-env-var

Conversation

@matt-dz
Copy link
Copy Markdown
Collaborator

@matt-dz matt-dz commented Apr 3, 2026

Summary

Agents and users currently have no way to discover which directories are accessible via the sandbox. This PR sets ALLOWED_PATHS in the interpreter's environment via setVarString in Reset, so users can run echo $ALLOWED_PATHS to see a delimited list of allowed directories.

  • Sandbox.Paths() returns the resolved absolute paths of all allowed directories
  • ALLOWED_PATHS is set alongside PWD, IFS, OPTIND using filepath.ListSeparator (: on Unix, ; on Windows)
  • Non-existent paths that were skipped during construction do not appear
  • The variable is always set when a sandbox exists (empty string if no valid roots)
  • Documented in SHELL_FEATURES.md

Test plan

  • Unit tests: two paths, single path, five paths, nested dirs, parent+child, skips nonexistent, not set without sandbox
  • Scenario test: echo $ALLOWED_PATHS contains directory names
  • Full test suite passes (allowedpaths, interp, tests, analysis)
  • CI passes

🤖 Generated with Claude Code

Set ALLOWED_PATHS in the interpreter's environment during construction
so users/agents can discover accessible directories via echo $ALLOWED_PATHS.
The value is a filepath.ListSeparator-delimited list of resolved absolute
paths (skipping non-existent ones).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@matt-dz
Copy link
Copy Markdown
Collaborator Author

matt-dz commented Apr 3, 2026

@codex conduct a comprehensive security and code review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9fb2e1f431

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread interp/api.go Outdated
Store raw env pairs on runnerConfig and build ListEnviron once in New()
with ALLOWED_PATHS appended. This avoids the environToList roundtrip
that could lose state from custom Environ implementations.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@matt-dz
Copy link
Copy Markdown
Collaborator Author

matt-dz commented Apr 3, 2026

@codex conduct a comprehensive security and code review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dd468bb34e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread interp/api.go Outdated
@matt-dz
Copy link
Copy Markdown
Collaborator Author

matt-dz commented Apr 3, 2026

@codex conduct a comprehensive security and code review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dd468bb34e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread interp/api.go Outdated
@matt-dz
Copy link
Copy Markdown
Collaborator Author

matt-dz commented Apr 3, 2026

@codex conduct a comprehensive security and code review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dd468bb34e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread interp/api.go Outdated
Instead of rebuilding Env at construction time, set ALLOWED_PATHS
through the writeEnv overlay in Reset — the same mechanism used for
PWD, IFS, and OPTIND. This removes the envPairs field, the
environToList helper, and all Environ rebuilding logic.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@matt-dz
Copy link
Copy Markdown
Collaborator Author

matt-dz commented Apr 3, 2026

@codex conduct a comprehensive security and code review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2f1bcfaf4b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread interp/api.go Outdated
Set ALLOWED_PATHS to empty string when the sandbox has zero valid
roots, preventing a spoofed value from Env() leaking through.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@matt-dz
Copy link
Copy Markdown
Collaborator Author

matt-dz commented Apr 3, 2026

@codex conduct a comprehensive security and code review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 76fecad9f6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread interp/api.go
@matt-dz
Copy link
Copy Markdown
Collaborator Author

matt-dz commented Apr 3, 2026

@codex conduct a comprehensive security and code review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 76fecad9f6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread interp/api.go
@matt-dz
Copy link
Copy Markdown
Collaborator Author

matt-dz commented Apr 3, 2026

@codex conduct a comprehensive security and code review. The variable quota concern from the previous round has been addressed and can be ignored.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 76fecad9f6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread interp/api.go
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@matt-dz
Copy link
Copy Markdown
Collaborator Author

matt-dz commented Apr 3, 2026

@codex conduct a comprehensive security and code review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1667c84de9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread interp/api.go
@matt-dz
Copy link
Copy Markdown
Collaborator Author

matt-dz commented Apr 3, 2026

@codex conduct a comprehensive security and code review. The variable quota concern from the previous round has been addressed and can be ignored.

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@matt-dz matt-dz marked this pull request as ready for review April 3, 2026 20:14
@matt-dz matt-dz requested review from astuyve and val06 as code owners April 3, 2026 20:14
@matt-dz matt-dz enabled auto-merge April 3, 2026 20:14
"os.Pipe", // 🟠 creates an OS pipe pair; needed for shell pipelines.
"path/filepath.IsAbs", // 🟢 checks if path is absolute; pure function, no I/O.
"path/filepath.Join", // 🟢 joins path elements; pure function, no I/O.
"path/filepath.ListSeparator", // 🟢 OS-specific path list separator; pure constant.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually what we want? I think for lists in shell scripting you usually space-separate them, this I think is for constructing known variables like PATH that have a specific format

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it's a clean separation between filepaths. i avoided spaces because i'm worried about file paths/directories with spaces in them. but if that's the case then i can change

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair, I guess what we really want here is an "array" type like in Bash, but not sure whether we can support that in our interp. Is it going to be able to iterate over them if they're colon-separated though? It might need to use tr to do that?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was imagining the agent doing something like echo $ALLOWED_PATHS and inferring the result from there. I believe even if it does something like splitting the result with tr and printing each directory on a line, the result from PAR gets sent back with a \n effectively acting as the same delimiter. so /path/a:/path/b:path/c -> /path/a\n/path/b\n/path/b.

Alternatively, it could just not do string manipulation and return the result but then whether it is a : or a space delimiting the list, I believe the LLM should be able to infer the result (we can probably edit the skill to let it know that it will be delimited by a special character).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I was imagining it doing something like "loop over the paths and call ls on each one" as a single pass. Agree if the value makes it back to the LLM it'll be able to figure it out, just wanted to cut out that roundtrip if possible.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah i see. i think we can just merge and if we see the LLM having trouble we can rethink?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'll be a pain to change later so it's probably worth at least seeing how the LLMs are likely to try to use this list to determine whether there are any gaps in our coverage. Here's some anecdata, does rshell support either of these?

Image

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, both work

$ ./rshell --allowed-paths /var/log,/tmp/,/Users/matthew.deguzman --allow-all-commands -c 'IFS=":"; for dir in $ALLOWED_PATHS; do echo "$dir"; done'
/var/log
/tmp
/Users/matthew.deguzman

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Word, send it

Copy link
Copy Markdown
Collaborator

@thieman thieman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM other than the question on the separator

@matt-dz matt-dz disabled auto-merge April 3, 2026 20:50
@matt-dz matt-dz enabled auto-merge April 3, 2026 20:50
@matt-dz matt-dz added this pull request to the merge queue Apr 3, 2026
Merged via the queue into main with commit 6ff3d76 Apr 3, 2026
33 of 34 checks passed
@matt-dz matt-dz deleted the matt-dz/allowed-paths-env-var branch April 3, 2026 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants