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, and 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 capture and display output from executed code.
  Environment environment = new Environment("example_path");
  assert environment.execute("example.py", "print('Hello, World!')", false).contains("Hello, World!");
  assert environment.analyze("example.py", "import os; os.getcwd()").get("imports").contains("os");
  assert environment.analyze("example.py", "x = 10; y = 20").get("variables_set").contains("x", "y");
  assert environment.execute("example.py", "x = 10; print(x)", true).contains("10");
  assert environment.execute("empty.py", "").isEmpty();
output: def execute(self, filename, code, capture_output):
      self.globals = {}
      self.stdout = ""
      def capture_print(*args):
          nonlocal self.stdout
          self.stdout += " ".join(map(str, args)) + "\n"
      self.globals['print'] = capture_print
      exec(code, self.globals)
      return self.stdout.strip() if capture_output else ""
  
  def analyze(self, filename, code):
      self.globals = {}
      exec(code, self.globals)
      imports = [k for k in self.globals if k.startswith('__import__')]
      variables_set = [k for k in self.globals if not k.startswith('__') and k != 'print']
      return {"imports": imports, "variables_set": variables_set}