For my computer science uni project I'm required to build a web application with an integrated code editor. I believe I can just integrate open source editors like Ace Editor.

However, I feel blocked at this stage because I'm unsure what the next step should be. Say that the user enters some Python code that should be executed... how could I accomplish this?

I'm assuming I'd send the code as a string to my server. But after this, I wouldn't know how to execute that code then display the results to the user on the client side. Apologies if this is a simple question but I couldn't find an agreed upon solution online but I know it's accomplishable as platforms like Repl.it, Codecademy and Hackerrank have achieved this.

This solution should be applicable to other languages I have learnt in my degree like C++, Java, JavaScript along with python of course. Literally any help would be appreciated as my lecturers aren't really well versed in the practical aspects of computer science like programming/development.


The extremely simplified version of things would be to capture the text from the editor, and send it back to the server. Then on the server save that text into a file on the server. From there, execute the code like you normally would, and capture its output, either in a file, or in a process that then writes the output back to the client. When the client receives the output, it displays it appropriately (e.g., a separate editor window with syntax highlighting).

To keep the user from destroying the server, you probably want to (if necessary compile and) execute the user's code in a virtual machine, or at least a container. You probably also want to limit the amount of memory and (especially) CPU time they can use. You probably also want to limit their ability to open files, write to the server's storage, etc.

If you're willing to put in some work, you may be able to put together a reasonably secure system on your own. For one example, the owner/operator of coliru has placed its source code on line.

  • That workflow makes sense. My last cause of concern would be as to how I can actually compile and execute the code. If I were to have the C++ code in a file on my server. Would I be able to command my server(in nodejs) to run a command similar to 'g++ myfile.cpp' ? I'm not aware if we can do this but if you are aware then please send over some pointers/links to resources. Happy to upvote your response then :) – Sonjeet Paul Oct 26 at 15:05
  • 1
    @SonjeetPaul I don't use node, but I'd bet it supports running commands. – Jerry Coffin Oct 26 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.