Owen
Owen

Reputation: 7098

Sandboxed scripting

I'm interested in how I could use a scripting language to execute simple blocks of code in a sandboxed manner. 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 programming constructs i.e. conditionals/loops/date manipulation/arrays etc. But what I don't want is to expose things such as IO, connectivity to http streams, databases etc.

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

Upvotes: 6

Views: 1335

Answers (2)

dubiousjim
dubiousjim

Reputation: 4802

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.

Upvotes: 2

Cheeso
Cheeso

Reputation: 192457

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.

Upvotes: 1

Related Questions