diff --git a/activity.py b/activity.py index 25fd64d..8ce5786 100644 --- a/activity.py +++ b/activity.py @@ -372,17 +372,19 @@ def display_activity_metadata(room_name, username): def execute_processing_script(metadata, script): - # Prepare the local environment for the script - local_env = { + # Prepare the environment for the script + # Use the same dict for both globals and locals to support comprehensions + script_env = { + "__builtins__": __builtins__, "metadata": metadata, "script_result": None, } # Execute the script - exec(script, {}, local_env) + exec(script, script_env, script_env) # Return the result from the script - return local_env["script_result"] + return script_env["script_result"] def handle_activity_response(room_name, user_response, username, model="MODEL_0"): diff --git a/research/guarded_ai.py b/research/guarded_ai.py index b0526ad..8b85c22 100644 --- a/research/guarded_ai.py +++ b/research/guarded_ai.py @@ -297,14 +297,19 @@ def provide_feedback_prompts( def execute_processing_script(metadata, script): - # Prepare the local environment for the script - local_env = {"metadata": metadata, "script_result": None} + # Prepare the environment for the script + # Use the same dict for both globals and locals to support comprehensions + script_env = { + "__builtins__": __builtins__, + "metadata": metadata, + "script_result": None, + } # Execute the script - exec(script, {}, local_env) + exec(script, script_env, script_env) # Return the result from the script - return local_env["script_result"] + return script_env["script_result"] def get_next_section_and_step(activity_content, current_section_id, current_step_id):