# Sandboxing with elm

**URL:** <https://discourse.elm-lang.org/t/sandboxing-with-elm/1218>\
**Category:** Learn\
**Created:** [May 4, 2018, 1:06pm UTC](https://discourse.elm-lang.org/t/sandboxing-with-elm/1218 "2018-05-04T13:06:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rumkin](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/rumkin/32/935_2.png) [@rumkin](https://discourse.elm-lang.org/u/rumkin)\
**Post date:** [May 4, 2018, 1:06pm UTC](https://discourse.elm-lang.org/t/sandboxing-with-elm/1218/1 "2018-05-04T13:06:31Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mfeineis](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/mfeineis/32/104_2.png) [@mfeineis](https://discourse.elm-lang.org/u/mfeineis)\
**Post date:** [May 4, 2018, 2:22pm UTC](https://discourse.elm-lang.org/t/sandboxing-with-elm/1218/2 "2018-05-04T14:22:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rumkin](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/rumkin/32/935_2.png) [@rumkin](https://discourse.elm-lang.org/u/rumkin)\
**Post date:** [May 4, 2018, 2:33pm UTC](https://discourse.elm-lang.org/t/sandboxing-with-elm/1218/3 "2018-05-04T14:33:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mfeineis](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/mfeineis/32/104_2.png) [@mfeineis](https://discourse.elm-lang.org/u/mfeineis)\
**Post date:** [May 4, 2018, 2:55pm UTC](https://discourse.elm-lang.org/t/sandboxing-with-elm/1218/4 "2018-05-04T14:55:36Z")

</div>

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

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

```auto
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 🙂

---

<div class="post-metadata">

**Author:** ![rumkin](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/rumkin/32/935_2.png) [@rumkin](https://discourse.elm-lang.org/u/rumkin)\
**Post date:** [May 4, 2018, 3:15pm UTC](https://discourse.elm-lang.org/t/sandboxing-with-elm/1218/5 "2018-05-04T15:15:21Z")

</div>

> 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 😀

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.

---

<div class="post-metadata">

**Author:** ![mfeineis](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/mfeineis/32/104_2.png) [@mfeineis](https://discourse.elm-lang.org/u/mfeineis)\
**Post date:** [May 4, 2018, 3:38pm UTC](https://discourse.elm-lang.org/t/sandboxing-with-elm/1218/6 "2018-05-04T15:38:08Z")

</div>

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 🙂

```auto
// App1.elm
// Have a headless Elm program
main =
    Platform.programWithFlags
        { init = init
        , subscriptions = subscriptions
        , update = update
        }

```

```auto
// service.js
import Elm from 'your/built/app.js';
const app1 = Elm.App1.worker({ someFlag: true });
app1.ports.toElm.send({ your: 'data' });
// ... more apps

```

---

<div class="post-metadata">

**Author:** ![rumkin](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/rumkin/32/935_2.png) [@rumkin](https://discourse.elm-lang.org/u/rumkin)\
**Post date:** [May 4, 2018, 4:53pm UTC](https://discourse.elm-lang.org/t/sandboxing-with-elm/1218/7 "2018-05-04T16:53:34Z")

</div>

Thanks a lot 👍. I will return when get results.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)\
**Post date:** [May 14, 2018, 4:53pm UTC](https://discourse.elm-lang.org/t/sandboxing-with-elm/1218/8 "2018-05-14T16:53:47Z")

</div>

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