CodingBat provides exercises for Java and Python. Your code is actually run on the server. Generally, this is risky, because Python's dynamic nature makes it notoriously difficult to limit its powers. CodingBat does this aggressively, and manages it only because it limits the code it will run to very simple functions. For example, you cannot import anything.
Another server-side solution is the NCSS Challenge, which uses an elaborate sandboxing technique on the server to run arbitrary Python code. The sandbox is explained in this PyCon AU video by Tim Dawborn. It seems prohibitively complex, but makes it possible to run sophisticated Python code from the browser.
There are other server-side online Python execution pages:
- Python Web Console, which uses Jython (details here) so that Java sandboxing will keep the server safe.
- ScraperWiki Tutorials.
Server-side execution solve the problem of executing Python, but introduces the new problem of keeping the server safe. Can we instead execute Python in the browser? There have been some interesting implementations of this also:
- Try Python is an in-browser Python implementation using IronPython running in Silverlight. This limits its platform viability, somewhat blunting the benefits of in-browser execution. Also, most of the standard library is missing, and OS services are necessarily limited.
Reviewing all these possibilities, none are perfect, and some are far from it. And I started to wonder, are online exercises worth all this? After all, the point of learning a language is to eventually write your own code, and that won't happen in a sandbox in a browser. The student will have to install a real Python environment at some point, so why not start with that, and get a better learning environment right off the bat?
Are there other possibilities? Is it important? What about an environment on the student's computer that can communicate result back to the online environment automatically? Or an online environment that can use the student's local resources so the server doesn't need protection?