I have some knowledge of CGI scripts and how they work and came to thinking that, in theory, it should be possible to run VirtualBox, or any type of virtualization as a CGI script. Understandably, this would be no easy task. For one thing, it’s output (the screen of the virtual OS) would somehow have to be converted so that the browser could read it, show it to the user, and then somehow update it without refreshing the page (which would mean JavaScript would be involved, probably).
Does anyone have any suggestions on how one would start a project such as this one? Has this been done/attempted before?
First of all, running a virtual machine as a CGI script is highly unpractical, as it would stop the machine if the connection is broken. Instead, the CGI script should be able to start, stop and control the virtual machine, which would be running in the background.
As for interacting with the virtual machine, VirtualBox has support for remote desktops (through the VNC protocol), which is probably the most suitable method of displaying and controlling it. However, while you can use a combination of server-side and client-side scripting to make this work, this would probably become very slow and use a lot of bandwidth. Instead, you could use something like a Java applet to connect directly to the virtual machine via VNC, which would save much of the hasstle on the server side.
There is also a similar idea called phpvirtualbox, which I haven’t look into myself, but you might find it interesting.