/
Code execution

Code execution

One of the main features Structs.sh wishes to push out this year is the visual debugger that takes student’s C code of data structures & algorithm to visualize is to them. The main challenge is in converting that user C code into shapes and lines that aid students in their learning.

 

Compiling and execution

We should aim for compilation and execution of user code to be

  • Secure: the server should be able to withstand infinite loops + forkbombs. Also, resources should be fairly allocated (a person shouldn’t be able to hog up server resources with an infinite loop. slowing down everyone else’s experience

  • Fast: Ideally, it shouldn’t take longer than 5-10 seconds for a visualization to show up

Possible approaches

We may need an API for code execution

This video is a godsend (video about how piston was made, discord bot uses it for code execution): https://www.youtube.com/watch?v=SD4KgwdjmdI&t=660s&ab_channel=EngineerMan

Docker

We can execute programs in a docker container: because the code is executed in an isolated container, malicious code shouldn’t be able to shut down the entire server. Can also set resource limits.

algorithm-visualizer https://github.com/algorithm-visualizer/server/tree/master/src/tracers uses this approach for C/C++ code execution

AWS Lambda

imma be honest i have no clue what this is i’ll maybe look more into it later and update this

WASM

We can use web assembly to compile and execute code. WASM can run on the browser, so this eliminates the need for a backend server. https://blog.wokwi.com/running-gdb-in-the-browser/

Related content