bytecodealliance / bytecodealliance/componentize-py

Allow dynamic imports in sandbox example

未关闭
#91 10 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Rust
星标
277
派生
51
平均合并
12 小时 10 分钟
30 天内合并 PR
10

描述

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)
```

贡献指南

打开贡献指南

调研方向

从 sandbox 示例的 Run.run 入口点开始,尤其关注它读取 guest 代码并调用 exec 的位置。分别在 host 端导入和不导入 json 的情况下运行所示的 guest 程序,然后跟踪 import 行为。当 guest 代码可以动态导入 json,而不要求 host 脚本先导入它时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
security
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。