# Accessing binding in eval with $SAFE=4

**URL:** <https://www.ruby-forum.com/t/accessing-binding-in-eval-with-safe-4/129186>\
**Category:** Ruby\
**Created:** [February 15, 2008, 6:55am UTC](https://www.ruby-forum.com/t/accessing-binding-in-eval-with-safe-4/129186 "2008-02-15T06:55:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ngrandy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/4bbf92/32.png) [@ngrandy](https://www.ruby-forum.com/u/ngrandy)\
**Post date:** [February 15, 2008, 6:55am UTC](https://www.ruby-forum.com/t/accessing-binding-in-eval-with-safe-4/129186/1 "2008-02-15T06:55:44Z")

</div>

hi all,  
can anyone explain why this doesn’t work?

class MyBinding  
def my\_test  
“success!”  
end  
end

b = MyBinding.new.instance\_eval{binding}

thread = Thread.start do  
$SAFE = 4  
cmd = ‘my\_test’  
result = eval(cmd, b)  
end  
p thread.value

i know i can’t modify the binding object in $SAFE=4, but i thought i  
could access it at least. what is an alternate approach? i am trying  
to execute code in a safe(ish) way within a context of my choice.  
thanks,  
nick
