#API to receive and then run Go code

17 messages · Page 1 of 1 (latest)

crimson tapir
#

i am trying to make a website that has questions like

Write an algorithm that takes in two integers a and b, and returns the sum as a result

and then the user inputs the code and submits it like a form, then the back-end runs the code against some test cases and returns the result. how can i do that in Go, and for Go code ideally?

midnight imp
# crimson tapir maybe https://github.com/traefik/yaegi?

It's not a trivial thing to do, either try to use that, or like the #bot-testing bot does, you can send the code to the playground, another option is to actually write that into a file, compile and run, but then sandboxing is a pain

crimson tapir
midnight imp
#

The go team made a 'playground' which lets users run code online https://go.dev/play/
So they already went into the trouble of sandboxing everything and making it safe, so the bot in #bot-testing just takes the code that you give it, formats it a bit, and send it to be run on the playground and returns the results

crimson tapir
midnight imp
#

Yes

#

because there's a lot of pitfalls when letting users run code on your machine, what if they make an infinite loop? what if they try accessing files in the filesystem?

crimson tapir
#

so there's no other easy way of sandboxing it?

#

but my project is actually all run locally

#

by the user

#

so it's not a huge issue

crimson tapir
sage star
crimson tapir
#

they are running the website locally

#

it's for students to play around with