This has been done, so it's certainly possible. In fact, there are sites, like koding.com and cloud9.io that have in-browser bash command lines.
I would venture, though I don't know for sure that with javascript, some ajax magic and some kind of server-side scripting language (PHP, Ruby, ASP...