Sandboxing with elm

Hi I’m searching a way to make sandbox with Elm. But I need to now two things:

  • How to run two instances of one program?
  • Is it possible to serialize/deserialize program state to create/restore memory dumps?
  • Is there any debugger to reproduce step-by-step execution and pauses on breakpoint?

I don’t understand the question, what do you mean by “make sandbox with Elm”?

I need a way to run untrusted code delivered by network. And I’m going to use Elm for that. Because it allows to make sandboxed code interaction predictable and strict.

So you basically want to use Elm as a scripting language where your backend?/frontend? will execute code that isn’t trustworthy because it is delivered over a network? To do what sort of work?

You can embed two Elm programs into the DOM

const app1 = Elm.App1.embed(document.querySelector('#root1'));
const app2 = Elm.App2.embed(document.querySelector('#root2'));

There is also the possibility to run an Elm app inside a WebWorker

const worker = new Worker('your-elm-app.js')
const app = Elm.Main.fullscreen();

Something exotic would be to create an iframe via JS that loads another app.

You can indeed de-/serialize your whole state and put that through a port.

There is no Elm debugger I know of, you could step through the emitted JS source but that would be rather tedious.

Without more details it’s hard to tell what you may need exactly :slight_smile:

To do what sort of work?

Handle JSON and store values.

Without more details it’s hard to tell what you may need exactly

I’m on research stage so it’s harder to provide more details :grinning:

I’m going to run elm program with nodejs. For example I have counter app which increase stored value. This app should work like service and subscribe to some counter Port. I’m going to run several instances of such program in one nodejs process simultaneously.

That would be possible, although it’s a curious thing that you want to process JSON with Elm when de-/encoding JSON is one of the things people constantly complain about :slight_smile:

// App1.elm
// Have a headless Elm program
main =
    Platform.programWithFlags
        { init = init
        , subscriptions = subscriptions
        , update = update
        }
// service.js
import Elm from 'your/built/app.js';
const app1 =  Elm.App1.worker({ someFlag: true });
app1.ports.toElm.send({ your: 'data' });
// ... more apps

Thanks a lot :+1:. I will return when get results.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.