bytecodealliance / bytecodealliance/componentize-py
Allow dynamic imports in sandbox example
- Dominant language
- Rust
- Stars
- 277
- Forks
- 51
- Avg merge
- 12h 10m
- Merged PRs (30d)
- 10
Description
I'd like to execute code using the sandbox example, but am running into an issue. I want to allow exec'd code to import packages, but if I don't import packages in the host script, the guest code won't run.
```python
# Guest code
import json
print(json.dumps({"message": "Hello"}))
```
```python
# Works
import sys
import json
from command import exports
class Run(exports.Run):
def run(self):
with open(sys.argv[1]) as f:
code = f.read()
exec(code)
```
```python
# Fails
import sys
from command import exports
class Run(exports.Run):
def run(self):
with open(sys.argv[1]) as f:
code = f.read()
exec(code)
```
Contributor guide
Research direction
Start at the sandbox example's Run.run entry point, especially where it reads the guest code and calls exec. Run the shown guest program with and without the host-side json import, then trace the import behavior. Done means guest code can dynamically import json without requiring the host script to import it first.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- security
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100