# Safe domain specific language implementation

**URL:** <https://www.ruby-forum.com/t/safe-domain-specific-language-implementation/68060>\
**Category:** Ruby\
**Created:** [September 8, 2006, 8:20pm UTC](https://www.ruby-forum.com/t/safe-domain-specific-language-implementation/68060 "2006-09-08T20:20:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [September 8, 2006, 8:20pm UTC](https://www.ruby-forum.com/t/safe-domain-specific-language-implementation/68060/1 "2006-09-08T20:20:52Z")

</div>

Greeting All,

I am trying to write code that will interpret user submitted scripts in  
a secure way. I have a limited set of functions that they should be  
able to call to change various states. I also need the usual branching,  
loping, and local variable assignment types of things. (see example  
code) I hoped to be able to use Rubyâ??s safe mode for this is ways  
similar to [artima - Creating DSLs with Ruby](http://www.artima.com/rubycs/articles/ruby_as_dslP.html)

I have a few questions in this regard:

1). Are there any websites/articles that deal with how to use $SAFE  
(particularly level 4)

2). In light of [http://code.whytheluckystiff.net/sandbox/wiki](http://code.whytheluckystiff.net/sandbox/wiki) is this a  
feature that is still in development? (please also see  
[$SAFE =4 safe enough? - Ruby - Ruby-Forum](http://www.ruby-forum.com/topic/79295#131045))

3). What are some implementation options? What would be required in  
terms of programming?

Thanks

J.F. Miller

=====  
Example code

#entrusted user script

#call this function when a power shortage is detected  
def power\_shortfall  
pl = get\_power\_reading  
if pl\<100  
shutdown\_expermint  
else  
reduse\_load(1000-pl/10)  
end  
end
