views:

49

answers:

2

Im interested in how I could use a scripting language to execute simple blocks of code in a sandboxed manor. The host language/environment could be c#/ruby/python/java (anything but c). But the scripting language could equally be something obscure such as javascript/python/ruby/perl etc.

What I want is a way of executing script with traditional programing constructs i.e. conditionals/loops/date maipulation/arrays etc. But what I dont want is to expose things such as IO, connectivity to http streams, databases etc.

I'm currently looking at spidermonkey using the python adaptor, but I wondered if there were other options that I should consider.

Any advise welcome.

Cheers, Chris.

+1  A: 

You could do it with .NET (VB, C#, any language) via Code Access Security - set the policy on the machine to not allow access to any Framework classes you like.

See Setting Security Policy.

By default the policy allows code that originated on the local machine to do anything; you can set it so that by default, code cannot call into the I/O classes, cannot do HTTP connections, and so on.

Cheeso
On the back of this comment I started looking at boo I wanted an extensible language as well as some nice dynamism. I suddenly realize that the CLR is a great platform, and I believe that one day C# will be a java like dinosaur but the CLR will live for quite some time.
Owen
+1  A: 

Lua is very easy to sandbox code in. Here's a reference on the Lua wiki. It's a terrific minimalist scripting language, easy to embed in other (C or C++) code. So your host would be Lua embedded in some other code (or just the factory-installed Lua interpreter). Your scripting language would be Lua.

If you don't know it, though, I'm sure there are other good solutions that don't require you to learn a new language.

profjim