MCPcopy Create free account
hub / github.com/RoboCodeX-source/RoboCodeX_code / exec_safe

Function exec_safe

instruct_to_policy/scripts/src/utils.py:102–118  ·  view source on GitHub ↗
(code_str, gvars=None, lvars=None)

Source from the content-addressed store, hash-verified

100
101
102def exec_safe(code_str, gvars=None, lvars=None):
103 # Due to few shot and zero shot prompt, code might generate import, slack this contraint
104 # banned_phrases = ['import', '__']
105 # for phrase in banned_phrases:
106 # assert phrase not in code_str
107
108 if gvars is None:
109 gvars = {}
110 if lvars is None:
111 lvars = {}
112 empty_fn = lambda *args, **kwargs: None
113 custom_gvars = merge_dicts([
114 gvars,
115 {'exec': empty_fn, 'eval': empty_fn}
116 ])
117 # print(code_str)
118 exec(code_str, custom_gvars, lvars)
119
120
121

Callers 5

check_code_grammarFunction · 0.90
run_evalMethod · 0.90
__call__Method · 0.85
create_f_from_sigMethod · 0.85

Calls 1

merge_dictsFunction · 0.85

Tested by

no test coverage detected