Amber VM¶
Amber VM is a Virtual Machine written in Ruby - which also explains the abbreviation. The goal is to introduce secure and flexible scripting to ruby applications, in a way beyond what Ruby itself is currently capable of doing.
The idea spawned with rMUSH, a server for text based online RPG's, which has the requirement of allowing users to extend the server on the fly by scripting certain processes.
Allowing the use of ruby itself for this was out of question as certainly the users are not necessarily trustworthy of executing random code on the host machine. Hence users rights for the server are not given on a invited bases.
Also I wanted to allow users to choose between a variety of languages instead of being forced to use one and only one language.
Goals¶
Formulating the goals ended up on about this:
A way to introduce scripting that is:
- Secure, as in the executed code can't access the world around it's box. (given the interpreter running it has no bug)
- Expandable, as in allowing the application that uses it to extend the language on the fly and offer easy ways to add functions, data types and even own language definitions.
- Flexible, as in not restricting the user to one language, allowing to mix then and braking down the barriers between languages (for example writing a function in one language and using it from without another)
- Easy to use, as in not having to go through a huge load of pain to introduce scripting to a application.
Secure¶
Amber VM does not directly call any ruby functions, to give a script access to any function you'll have to publish it with a function plugin. Hence the shipped plugins are not even loaded on their own - save for some very basic sets that are required by the laoded languages and can be considered save (say mathematical and logical operations)
Additional there is a security model called AmberVM::Safety that allows to impose further restrictions on the executed time to prevent runaway code or DoS attacks.
Expandable¶
Amber VM is entirely plugin based, adding functions, types or even languages means nothing more as writing a ruby class and loading it into your program. The interface for those are hold as easy as possible to make it easier to coop with.
Flexible¶
Even Amber VM itself ships with currently 3 languages to choose from. Due to the design of the VM, and that each language is compiled towards a VM Code instead of interpreted straight ahead mixing them is not a problem at all. Within the SVN repository also is an example how to import libraries written and compiled by Amber VM into ruby.
Easy to use¶
As long as no custom classes and functions need to be required, nothing more then a few 'requires', and 4 lines of code to compile and execute scripts is required. No hassle with any big or complicated initialization, setting variables or such. If you just want the basics, it's ruby-simple!
Of cause no one stops you to dig deeper and figure what nifty things you can do with say own functions, or other funny things.
Experimental Things¶
- Fukubukuro - murphy's minimal interpreter
- Logical shift - an implementation of a logical shift operator