How might I connect to Minecraft from Snap?

You need to run /wsserver minecraft-server.warpedwartwars.repl.co

You can: pip install git+https://github.com/BluCodeGH/bedrock

You can write your own websocket server (those links are provided as a reference), the protocol isn't the most complicated...

The problem is that JSFunction runs cilentside code, not serverside. You can't create a server with that.

If you're modifying the world level file while the game is running, that'll probably create some interesting race conditions. If the game saves the file at the end, then your new save probably won't even register. If you want to edit it it while the game isn't running though, that could work.

As jens said: