Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a pyodide-based "sandbox" flavor #437

Merged
merged 4 commits into from
Mar 6, 2023
Merged

add a pyodide-based "sandbox" flavor #437

merged 4 commits into from
Mar 6, 2023

Conversation

paulfitz
Copy link
Member

@paulfitz paulfitz commented Feb 22, 2023

This adds a new GRIST_SANDBOX_FLAVOR=pyodide option where the version of Python used for the data engine is compiled to wasm, and so can be run by node like the rest of the back end. It still runs as a separate process.

There are a few small version changes made to packages to avoid various awkwardness present in the current versions.

This is very experimental. To use, you'll need something with a bash shell and make. First do:

cd sandbox/pyodide
make setup           # README.md and Makefile have details
cd ..

Then running Grist as:

GRIST_SANDBOX_FLAVOR=pyodide yarn start

should work. Adding a formula with content:

import sys; return sys.version

should return a different Python version than other sandboxes.

I haven't done much in the way of benchmarking. The sandbox has an extra startup time somewhat comparable to runsc. It feels usable on moderate sized docs on my Linux machine. Felt maybe a little sluggish on an older Mac?

The motivation for this work is to have a form of sandboxing that will work on Windows for Grist Electron (for Linux we have gvisor/runsc, for Mac we have sandbox-exec, but I haven't found anything comparable for Windows). Pyodide doesn't actually make any security promises I've found when running on node so I'm not making any claims either at this time.

It also brings a back-end-free version of Grist a bit closer, for use-cases where that would make sense - such as serving a report (in the form of a Grist document) on a static site.

The Pyodide version I used currently offers Python 3.10, which is different from our current standard of 3.9. I haven't added any automated tests for this sandbox flavor yet.

This adds a new `GRIST_SANDBOX_FLAVOR=pyodide` option where the
version of Python used for the data engine is wasm, and so can
be run by node like the rest of the back end. It still runs as
a separate process.

There are a few small version changes made to packages to avoid
various awkwardnesses present in the current versions. All existing
tests pass.

This is very experimental. To use, you'll need something with
a bash shell and make. First do:
```
cd sandbox/pyodide
make setup           # README.md and Makefile have details
cd ..
```

Then running Grist as:
```
GRIST_SANDBOX_FLAVOR=pyodide yarn start
```
should work. Adding a formula with content:
```
import sys; return sys.version
```
should return a different Python version than other sandboxes.

The motivation for this work is to have a form of sandboxing
that will work on Windows for Grist Electron (for Linux we have
gvisor/runsc, for Mac we have sandbox-exec, but I haven't found
anything comparable for Windows).

It also brings a back-end-free version of Grist a bit closer, for
use-cases where that would make sense - such as serving a report
(in the form of a Grist document) on a static site.
@paulfitz
Copy link
Member Author

(@georgegevoian I added two commits based on tests on using this on Windows)

@paulfitz
Copy link
Member Author

paulfitz commented Mar 6, 2023

@georgegevoian I've been using this branch quite a bit in follow up work. The python changes work well for pyodide-from-a-web-worker also. For the web, it is proving more practical to package up the date engine code as a wheel than to try and mount it. That means in follow-up I could rip out the mounting code which got a little ugly because of the Windows directory copy wrinkle (which is maybe related to some nuance of user id / permission handling?).

Copy link
Contributor

@georgegevoian georgegevoian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working fine on my end. Thanks @paulfitz.

@paulfitz paulfitz merged commit 66643a5 into main Mar 6, 2023
@paulfitz paulfitz deleted the pyodide branch March 6, 2023 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants