fix type-object marshalling across the sandbox boundary#478
Open
samuelcolvin wants to merge 3 commits into
Open
fix type-object marshalling across the sandbox boundary#478samuelcolvin wants to merge 3 commits into
samuelcolvin wants to merge 3 commits into
Conversation
Modeled stdlib type objects (PosixPath, datetime.*, re.*, io.*, …) were reconstructed host-side via getattr(builtins, name), raising AttributeError since they don't live in builtins. They now resolve from their real defining module, each cached in its own PyOnceLock. The Path class maps to PurePosixPath, consistent with how Path instances round-trip. Also fix the inverse direction: a type object passed into the sandbox (input or external-call return) previously degraded to a callable; recognized builtins and modeled stdlib types are now preserved as MontyObject::Type so they round-trip and isinstance works inside the sandbox. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Merging this PR will not alter performance
Comparing Footnotes
|
Contributor
There was a problem hiding this comment.
2 issues found across 6 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Codecov Results 📊✅ Patch coverage is 100.00%. Project has 24061 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 66.09% 66.36% +0.27%
==========================================
Files 281 281 —
Lines 71447 71521 +74
Branches 153474 153638 +164
==========================================
+ Hits 47218 47460 +242
- Misses 24229 24061 -168
- Partials 4043 4067 +24Generated by Codecov Action |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
The inbound (host → sandbox) type-object detection matched on (__module__, __name__) strings, which is both spoofable and version-fragile: pathlib path classes report __module__ as `pathlib._local` on Python 3.13, so PurePosixPath wasn't recognised and the round-trip test failed in CI. Switch to type-object identity matching against a cached table built from type_object_to_py, so the two directions stay in lock-step and a class that forges __name__/__module__ can't impersonate a builtin. The pathlib family is matched via issubclass(PurePath). Also preserve NoneType and ellipsis, which previously fell through to the callable fallback. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Modeled stdlib type objects (PosixPath, datetime., re., io.*, …) were reconstructed host-side via getattr(builtins, name), raising AttributeError since they don't live in builtins. They now resolve from their real defining module, each cached in its own PyOnceLock. The Path class maps to PurePosixPath, consistent with how Path instances round-trip.
Also fix the inverse direction: a type object passed into the sandbox (input or external-call return) previously degraded to a callable; recognized builtins and modeled stdlib types are now preserved as MontyObject::Type so they round-trip and isinstance works inside the sandbox.
Summary by cubic
Fixes type-object marshalling across the sandbox boundary so modeled stdlib types resolve from their real modules and incoming host types are preserved by identity.
pathlib.Pathmaps topathlib.PurePosixPathfor consistency.datetime,re,io,typing(notbuiltins); mappathlib.Path→pathlib.PurePosixPath; cache each resolved class in its ownPyOnceLock.MontyObject::Type), matching by identity; match allpathlibviaissubclass(PurePath); also preserveNoneTypeandellipsis; unmodeled classes still degrade to callables.isinstance, and unconvertible-instance errors; updated limitations docs; exportedTypefrom the crate root.Written for commit b0d574d. Summary will update on new commits.