News for hackers. Stuff that matters.

How to allow users to execute code on my SaaS product server-side?

As the title states, I'd like to allow my users to execute arbitrary code they write on our servers. Obviously, this has major security implications.

What would be the best approach as far as containerizing + sandboxing the execution runtime, such that they can execute code from various languages like Python, Node.js, etc. without something "escaping" into our EC2 instances for instance (pun intended)

Obviously, this has been done (many times) before, so I'm curious if any of you have experience with this sort of thing and the best implementation. Are there any libraries, frameworks, etc. out there already for something like this?

( 6 comments | 6 points | on HN )
Re:How to allow users to execute code on my SaaS product ser... by plasma on Saturday July 30, 2022 @12:12AM (#32284222)
I’d look into a few things like https://firecracker-microvm.github.io/
Re:How to allow users to execute code on my SaaS product ser... by usgroup on Saturday July 30, 2022 @08:13AM (#32286187)
I ran a little app that required arbitrary latex execution and I think a similar set up would apply:

1. Run code in docker container.

2. Within container run code as unprivileged user.

3. SELinux harden container.

4. Don’t run container as admin if you don’t have to.

5 Specify CPU and memory allowance per container. Run container for make T time.

6. Use a queue to govern how containers are spun up.

7. Don’t reuse containers.

8. Dependent on language, configure compiler/interpreter to disallow risky features.

Re:How to allow users to execute code on my SaaS product ser... by gc22browsing on Saturday July 30, 2022 @06:52AM (#32285770)
Firstly, why do you need your users to write and run arbitary code on your servers? If your product is such that user access is needed, then publishing an API for access would appear to be a simpler approach.

Nevertheless, if you do need to do so, why not look into using FreeBSD with jails, etc? Alternatively you could spin-up a hosted VM on their behalf and have them use that. But anybody who can program could probably do that for themselves, thus my API suggestion as above.

Re:How to allow users to execute code on my SaaS product ser... by wmf on Friday July 29, 2022 @11:57PM (#32284153)
One option that was just announced is https://news.ycombinator.com/item?id=32240511
Re:How to allow users to execute code on my SaaS product ser... by _6zfa on Saturday July 30, 2022 @07:09AM (#32285869)
My employer, wasmer.io is doing exactly that. You can contact the CEO directly to discuss how it can solve your problems.
Re:How to allow users to execute code on my SaaS product ser... by joshxyz on Saturday July 30, 2022 @01:47AM (#32284577)
have you checked about firecracker vm?