bytecodealliance / bytecodealliance/componentize-py

Allow dynamic imports in sandbox example

Offen
#91 10 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Rust
Sterne
277
Forks
51
Ø Merge
12 Std. 10 Min.
Gemergte PRs (30 T.)
10

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.