input: Write a function to create an Environment object that can execute and analyze Python code. The environment includes a set of predefined global variables and functions, as well as the ability to add additional global variables. The environment can execute Python code and analyze it for variable usage and imports. The environment also includes a stdout object that can be used to capture and display output from executed code.
  assert create_environment("/path/to/directory") != None
  assert "print" in create_environment("/path/to/directory").globals
  assert "jsonify" in create_environment("/path/to/directory").globals
  assert create_environment("/path/to/directory").active.pop() != None
output: def create_environment(directory):
      import sys
      import os
      import json
      from io import StringIO
  
      class Environment:
          def __init__(self):
              self.globals = {
                  "print": print,
                  "jsonify": json.dumps
              }
              self.stdout = StringIO()
              self.active = []
  
          def execute(self, code):
              old_stdout = sys.stdout
              sys.stdout = self.stdout
              try:
                  exec(code, self.globals)
              finally:
                  sys.stdout = old_stdout
              self.active.append(self.stdout.getvalue())
              self.stdout.truncate(0)
              self.stdout.seek(0)
  
      env = Environment()
      env.globals["os"] = os
      env.globals["sys"] = sys
      env.globals["json"] = json
      return env