Avoid host imports during sandbox fn package discovery#1402
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 99862ae37f
ℹ️ 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".
99862ae to
1fe20a0
Compare
ApprovabilityVerdict: Needs human review Unable to check for correctness in cad4b9e. Changes module resolution logic in sandbox program utilities, introducing new nested module handling with custom path construction and new error conditions. While the intent is to avoid side effects from imports, the complexity of the resolution changes warrants careful review. You can customize Macroscope's approvability policy. Learn more. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1fe20a0076
ℹ️ 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".
1fe20a0 to
4ed235f
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4ed235f49e
ℹ️ 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".
4ed235f to
7795c22
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 7795c22. Configure here.
7795c22 to
f4973a8
Compare
f4973a8 to
cad4b9e
Compare

Motivation
importlib.util.find_spec()can import parent packages while resolving dottedprogram.fnrefs, which lets local__init__.pycode run on the host before the sandbox boundary.Description
program.fnref withimportlib.util.find_spec(). This avoids the parent-import behavior because the name passed tofind_spec()is not dotted.importlib.machinery.PathFinder.find_spec().plain_program.child:run, instead of silently treatingplain_program.pyas the package root.json,os.path, andcollections.abcas no-package cases.Testing
uv run ruff check --fix .uv run ruff formatuv run ty check verifiersuv run pre-commit run semgrep-v1-policy --config .pre-commit-config.yaml --all-filesuv run pytest tests/test_v1_runtime_lifecycle.py -k sandbox_fn_programuv run pre-commit run --all-filesNote
Medium Risk
Medium risk because it changes how
program.fndotted module refs are resolved (including new ImportError cases), which can affect which packages get installed into the sandbox and which refs are considered valid.Overview
Prevents host-side imports during sandbox
program.fnpackage discovery.sandbox_program_packagenow callsfind_spec()only on the top-level module and resolves dotted/nested modules viaPathFinderover computed search paths, avoiding executing local__init__.pycode on the host.Tightens resolution behavior by rejecting dotted children of single-file local modules (raising
ImportError) while preserving the existing behavior of treating stdlib/built-in/frozen modules (e.g.json,os.path,collections.abc) as no local package to install.Tests add regression coverage ensuring package discovery does not create side effects (
sys.modulesentries or marker files) and validating nested-package resolution and new error cases.Reviewed by Cursor Bugbot for commit cad4b9e. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Avoid host imports during sandbox function package discovery
sandbox_program_packagein sandbox_program_utils.py now resolves the root package spec viaimportlib.util.find_specwithout importing it, then usesPathFinder.find_specto resolve nested dotted paths against the root's search locations.module_source_pathsnow raisesImportErrorwhen a dotted child of a local module cannot be resolved, or when resolution yields a mismatched local module.sandbox_program_packagecorrectly returnsNonefor those cases.sys.modulesafter resolution, confirming no imports occur.Macroscope summarized cad4b9e.