We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Don't expose all params as shell environment variables by default
_Originally posted by @bpkroth in https://github.com/microsoft/MLOS/pull/557#discussion_r1374921396_
            

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `mlos_bench/mlos_bench/environments/script_env.py`
Content:
```
1 #
2 # Copyright (c) Microsoft Corporation.
3 # Licensed under the MIT License.
4 #
5 """
6 Base scriptable benchmark environment.
7 """
8 
9 import abc
10 import logging
11 import re
12 from typing import Dict, Iterable, Optional
13 
14 from mlos_bench.environments.base_environment import Environment
15 from mlos_bench.services.base_service import Service
16 from mlos_bench.tunables.tunable import TunableValue
17 from mlos_bench.tunables.tunable_groups import TunableGroups
18 
19 from mlos_bench.util import try_parse_val
20 
21 _LOG = logging.getLogger(__name__)
22 
23 
24 class ScriptEnv(Environment, metaclass=abc.ABCMeta):
25     """
26     Base Environment that runs scripts for setup/run/teardown.
27     """
28 
29     _RE_INVALID = re.compile(r"[^a-zA-Z0-9_]")
30 
31     def __init__(self,
32                  *,
33                  name: str,
34                  config: dict,
35                  global_config: Optional[dict] = None,
36                  tunables: Optional[TunableGroups] = None,
37                  service: Optional[Service] = None):
38         """
39         Create a new environment for script execution.
40 
41         Parameters
42         ----------
43         name: str
44             Human-readable name of the environment.
45         config : dict
46             Free-format dictionary that contains the benchmark environment
47             configuration. Each config must have at least the `tunable_params`
48             and the `const_args` sections. It must also have at least one of
49             the following parameters: {`setup`, `run`, `teardown`}.
50             Additional parameters:
51                 * `shell_env_params` - an array of parameters to pass to the script
52                   as shell environment variables, and
53                 * `shell_env_params_rename` - a dictionary of {to: from} mappings
54                   of the script parameters. If not specified, replace all
55                   non-alphanumeric characters with underscores.
56             If neither `shell_env_params` nor `shell_env_params_rename` are specified,
57             pass *all* parameters to the script.
58         global_config : dict
59             Free-format dictionary of global parameters (e.g., security credentials)
60             to be mixed in into the "const_args" section of the local config.
61         tunables : TunableGroups
62             A collection of tunable parameters for *all* environments.
63         service: Service
64             An optional service object (e.g., providing methods to
65             deploy or reboot a VM, etc.).
66         """
67         super().__init__(name=name, config=config, global_config=global_config,
68                          tunables=tunables, service=service)
69 
70         self._script_setup = self.config.get("setup")
71         self._script_run = self.config.get("run")
72         self._script_teardown = self.config.get("teardown")
73 
74         self._shell_env_params: Optional[Iterable[str]] = self.config.get("shell_env_params")
75         self._shell_env_params_rename: Dict[str, str] = self.config.get("shell_env_params_rename", {})
76 
77         results_stdout_pattern = self.config.get("results_stdout_pattern")
78         self._results_stdout_pattern: Optional[re.Pattern[str]] = \
79             re.compile(results_stdout_pattern) if results_stdout_pattern else None
80 
81     def _get_env_params(self) -> Dict[str, str]:
82         """
83         Get the *shell* environment parameters to be passed to the script.
84 
85         Returns
86         -------
87         env_params : Dict[str, str]
88             Parameters to pass as *shell* environment variables into the script.
89             This is usually a subset of `_params` with some possible conversions.
90         """
91         rename: Dict[str, str]  # {to: from} mapping of the script parameters.
92         if self._shell_env_params is None:
93             if self._shell_env_params_rename:
94                 # Only rename specified - use it.
95                 rename = self._shell_env_params_rename.copy()
96             else:
97                 # FIXME: We should not be exposing all params by default.
98                 # Neither `shell_env_params` nor rename are specified - use all params.
99                 rename = {self._RE_INVALID.sub("_", key): key for key in self._params}
100         else:
101             # Use `shell_env_params` and rename if specified.
102             rename = {self._RE_INVALID.sub("_", key): key for key in self._shell_env_params}
103             rename.update(self._shell_env_params_rename)
104 
105         return {key_sub: str(self._params[key]) for (key_sub, key) in rename.items()}
106 
107     def _extract_stdout_results(self, stdout: str) -> Dict[str, TunableValue]:
108         """
109         Extract the results from the stdout of the script.
110 
111         Parameters
112         ----------
113         stdout : str
114             The stdout of the script.
115 
116         Returns
117         -------
118         results : Dict[str, TunableValue]
119             A dictionary of results extracted from the stdout.
120         """
121         if not self._results_stdout_pattern:
122             return {}
123         _LOG.debug("Extract regex: '%s' from: '%s'", self._results_stdout_pattern, stdout)
124         return {key: try_parse_val(val) for (key, val) in self._results_stdout_pattern.findall(stdout)}
125
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/mlos_bench/mlos_bench/environments/script_env.py b/mlos_bench/mlos_bench/environments/script_env.py
--- a/mlos_bench/mlos_bench/environments/script_env.py
+++ b/mlos_bench/mlos_bench/environments/script_env.py
@@ -54,7 +54,7 @@
                   of the script parameters. If not specified, replace all
                   non-alphanumeric characters with underscores.
             If neither `shell_env_params` nor `shell_env_params_rename` are specified,
-            pass *all* parameters to the script.
+            *no* additional shell parameters will be passed to the script.
         global_config : dict
             Free-format dictionary of global parameters (e.g., security credentials)
             to be mixed in into the "const_args" section of the local config.
@@ -71,7 +71,7 @@
         self._script_run = self.config.get("run")
         self._script_teardown = self.config.get("teardown")
 
-        self._shell_env_params: Optional[Iterable[str]] = self.config.get("shell_env_params")
+        self._shell_env_params: Iterable[str] = self.config.get("shell_env_params", [])
         self._shell_env_params_rename: Dict[str, str] = self.config.get("shell_env_params_rename", {})
 
         results_stdout_pattern = self.config.get("results_stdout_pattern")
@@ -88,20 +88,8 @@
             Parameters to pass as *shell* environment variables into the script.
             This is usually a subset of `_params` with some possible conversions.
         """
-        rename: Dict[str, str]  # {to: from} mapping of the script parameters.
-        if self._shell_env_params is None:
-            if self._shell_env_params_rename:
-                # Only rename specified - use it.
-                rename = self._shell_env_params_rename.copy()
-            else:
-                # FIXME: We should not be exposing all params by default.
-                # Neither `shell_env_params` nor rename are specified - use all params.
-                rename = {self._RE_INVALID.sub("_", key): key for key in self._params}
-        else:
-            # Use `shell_env_params` and rename if specified.
-            rename = {self._RE_INVALID.sub("_", key): key for key in self._shell_env_params}
-            rename.update(self._shell_env_params_rename)
-
+        rename = {self._RE_INVALID.sub("_", key): key for key in self._shell_env_params}
+        rename.update(self._shell_env_params_rename)
         return {key_sub: str(self._params[key]) for (key_sub, key) in rename.items()}
 
     def _extract_stdout_results(self, stdout: str) -> Dict[str, TunableValue]:

{"golden_diff": "diff --git a/mlos_bench/mlos_bench/environments/script_env.py b/mlos_bench/mlos_bench/environments/script_env.py\n--- a/mlos_bench/mlos_bench/environments/script_env.py\n+++ b/mlos_bench/mlos_bench/environments/script_env.py\n@@ -54,7 +54,7 @@\n                   of the script parameters. If not specified, replace all\n                   non-alphanumeric characters with underscores.\n             If neither `shell_env_params` nor `shell_env_params_rename` are specified,\n-            pass *all* parameters to the script.\n+            *no* additional shell parameters will be passed to the script.\n         global_config : dict\n             Free-format dictionary of global parameters (e.g., security credentials)\n             to be mixed in into the \"const_args\" section of the local config.\n@@ -71,7 +71,7 @@\n         self._script_run = self.config.get(\"run\")\n         self._script_teardown = self.config.get(\"teardown\")\n \n-        self._shell_env_params: Optional[Iterable[str]] = self.config.get(\"shell_env_params\")\n+        self._shell_env_params: Iterable[str] = self.config.get(\"shell_env_params\", [])\n         self._shell_env_params_rename: Dict[str, str] = self.config.get(\"shell_env_params_rename\", {})\n \n         results_stdout_pattern = self.config.get(\"results_stdout_pattern\")\n@@ -88,20 +88,8 @@\n             Parameters to pass as *shell* environment variables into the script.\n             This is usually a subset of `_params` with some possible conversions.\n         \"\"\"\n-        rename: Dict[str, str]  # {to: from} mapping of the script parameters.\n-        if self._shell_env_params is None:\n-            if self._shell_env_params_rename:\n-                # Only rename specified - use it.\n-                rename = self._shell_env_params_rename.copy()\n-            else:\n-                # FIXME: We should not be exposing all params by default.\n-                # Neither `shell_env_params` nor rename are specified - use all params.\n-                rename = {self._RE_INVALID.sub(\"_\", key): key for key in self._params}\n-        else:\n-            # Use `shell_env_params` and rename if specified.\n-            rename = {self._RE_INVALID.sub(\"_\", key): key for key in self._shell_env_params}\n-            rename.update(self._shell_env_params_rename)\n-\n+        rename = {self._RE_INVALID.sub(\"_\", key): key for key in self._shell_env_params}\n+        rename.update(self._shell_env_params_rename)\n         return {key_sub: str(self._params[key]) for (key_sub, key) in rename.items()}\n \n     def _extract_stdout_results(self, stdout: str) -> Dict[str, TunableValue]:\n", "issue": "Don't expose all params as shell environment variables by default\n_Originally posted by @bpkroth in https://github.com/microsoft/MLOS/pull/557#discussion_r1374921396_\r\n            \n", "before_files": [{"content": "#\n# Copyright (c) Microsoft Corporation.\n# Licensed under the MIT License.\n#\n\"\"\"\nBase scriptable benchmark environment.\n\"\"\"\n\nimport abc\nimport logging\nimport re\nfrom typing import Dict, Iterable, Optional\n\nfrom mlos_bench.environments.base_environment import Environment\nfrom mlos_bench.services.base_service import Service\nfrom mlos_bench.tunables.tunable import TunableValue\nfrom mlos_bench.tunables.tunable_groups import TunableGroups\n\nfrom mlos_bench.util import try_parse_val\n\n_LOG = logging.getLogger(__name__)\n\n\nclass ScriptEnv(Environment, metaclass=abc.ABCMeta):\n    \"\"\"\n    Base Environment that runs scripts for setup/run/teardown.\n    \"\"\"\n\n    _RE_INVALID = re.compile(r\"[^a-zA-Z0-9_]\")\n\n    def __init__(self,\n                 *,\n                 name: str,\n                 config: dict,\n                 global_config: Optional[dict] = None,\n                 tunables: Optional[TunableGroups] = None,\n                 service: Optional[Service] = None):\n        \"\"\"\n        Create a new environment for script execution.\n\n        Parameters\n        ----------\n        name: str\n            Human-readable name of the environment.\n        config : dict\n            Free-format dictionary that contains the benchmark environment\n            configuration. Each config must have at least the `tunable_params`\n            and the `const_args` sections. It must also have at least one of\n            the following parameters: {`setup`, `run`, `teardown`}.\n            Additional parameters:\n                * `shell_env_params` - an array of parameters to pass to the script\n                  as shell environment variables, and\n                * `shell_env_params_rename` - a dictionary of {to: from} mappings\n                  of the script parameters. If not specified, replace all\n                  non-alphanumeric characters with underscores.\n            If neither `shell_env_params` nor `shell_env_params_rename` are specified,\n            pass *all* parameters to the script.\n        global_config : dict\n            Free-format dictionary of global parameters (e.g., security credentials)\n            to be mixed in into the \"const_args\" section of the local config.\n        tunables : TunableGroups\n            A collection of tunable parameters for *all* environments.\n        service: Service\n            An optional service object (e.g., providing methods to\n            deploy or reboot a VM, etc.).\n        \"\"\"\n        super().__init__(name=name, config=config, global_config=global_config,\n                         tunables=tunables, service=service)\n\n        self._script_setup = self.config.get(\"setup\")\n        self._script_run = self.config.get(\"run\")\n        self._script_teardown = self.config.get(\"teardown\")\n\n        self._shell_env_params: Optional[Iterable[str]] = self.config.get(\"shell_env_params\")\n        self._shell_env_params_rename: Dict[str, str] = self.config.get(\"shell_env_params_rename\", {})\n\n        results_stdout_pattern = self.config.get(\"results_stdout_pattern\")\n        self._results_stdout_pattern: Optional[re.Pattern[str]] = \\\n            re.compile(results_stdout_pattern) if results_stdout_pattern else None\n\n    def _get_env_params(self) -> Dict[str, str]:\n        \"\"\"\n        Get the *shell* environment parameters to be passed to the script.\n\n        Returns\n        -------\n        env_params : Dict[str, str]\n            Parameters to pass as *shell* environment variables into the script.\n            This is usually a subset of `_params` with some possible conversions.\n        \"\"\"\n        rename: Dict[str, str]  # {to: from} mapping of the script parameters.\n        if self._shell_env_params is None:\n            if self._shell_env_params_rename:\n                # Only rename specified - use it.\n                rename = self._shell_env_params_rename.copy()\n            else:\n                # FIXME: We should not be exposing all params by default.\n                # Neither `shell_env_params` nor rename are specified - use all params.\n                rename = {self._RE_INVALID.sub(\"_\", key): key for key in self._params}\n        else:\n            # Use `shell_env_params` and rename if specified.\n            rename = {self._RE_INVALID.sub(\"_\", key): key for key in self._shell_env_params}\n            rename.update(self._shell_env_params_rename)\n\n        return {key_sub: str(self._params[key]) for (key_sub, key) in rename.items()}\n\n    def _extract_stdout_results(self, stdout: str) -> Dict[str, TunableValue]:\n        \"\"\"\n        Extract the results from the stdout of the script.\n\n        Parameters\n        ----------\n        stdout : str\n            The stdout of the script.\n\n        Returns\n        -------\n        results : Dict[str, TunableValue]\n            A dictionary of results extracted from the stdout.\n        \"\"\"\n        if not self._results_stdout_pattern:\n            return {}\n        _LOG.debug(\"Extract regex: '%s' from: '%s'\", self._results_stdout_pattern, stdout)\n        return {key: try_parse_val(val) for (key, val) in self._results_stdout_pattern.findall(stdout)}\n", "path": "mlos_bench/mlos_bench/environments/script_env.py"}], "after_files": [{"content": "#\n# Copyright (c) Microsoft Corporation.\n# Licensed under the MIT License.\n#\n\"\"\"\nBase scriptable benchmark environment.\n\"\"\"\n\nimport abc\nimport logging\nimport re\nfrom typing import Dict, Iterable, Optional\n\nfrom mlos_bench.environments.base_environment import Environment\nfrom mlos_bench.services.base_service import Service\nfrom mlos_bench.tunables.tunable import TunableValue\nfrom mlos_bench.tunables.tunable_groups import TunableGroups\n\nfrom mlos_bench.util import try_parse_val\n\n_LOG = logging.getLogger(__name__)\n\n\nclass ScriptEnv(Environment, metaclass=abc.ABCMeta):\n    \"\"\"\n    Base Environment that runs scripts for setup/run/teardown.\n    \"\"\"\n\n    _RE_INVALID = re.compile(r\"[^a-zA-Z0-9_]\")\n\n    def __init__(self,\n                 *,\n                 name: str,\n                 config: dict,\n                 global_config: Optional[dict] = None,\n                 tunables: Optional[TunableGroups] = None,\n                 service: Optional[Service] = None):\n        \"\"\"\n        Create a new environment for script execution.\n\n        Parameters\n        ----------\n        name: str\n            Human-readable name of the environment.\n        config : dict\n            Free-format dictionary that contains the benchmark environment\n            configuration. Each config must have at least the `tunable_params`\n            and the `const_args` sections. It must also have at least one of\n            the following parameters: {`setup`, `run`, `teardown`}.\n            Additional parameters:\n                * `shell_env_params` - an array of parameters to pass to the script\n                  as shell environment variables, and\n                * `shell_env_params_rename` - a dictionary of {to: from} mappings\n                  of the script parameters. If not specified, replace all\n                  non-alphanumeric characters with underscores.\n            If neither `shell_env_params` nor `shell_env_params_rename` are specified,\n            *no* additional shell parameters will be passed to the script.\n        global_config : dict\n            Free-format dictionary of global parameters (e.g., security credentials)\n            to be mixed in into the \"const_args\" section of the local config.\n        tunables : TunableGroups\n            A collection of tunable parameters for *all* environments.\n        service: Service\n            An optional service object (e.g., providing methods to\n            deploy or reboot a VM, etc.).\n        \"\"\"\n        super().__init__(name=name, config=config, global_config=global_config,\n                         tunables=tunables, service=service)\n\n        self._script_setup = self.config.get(\"setup\")\n        self._script_run = self.config.get(\"run\")\n        self._script_teardown = self.config.get(\"teardown\")\n\n        self._shell_env_params: Iterable[str] = self.config.get(\"shell_env_params\", [])\n        self._shell_env_params_rename: Dict[str, str] = self.config.get(\"shell_env_params_rename\", {})\n\n        results_stdout_pattern = self.config.get(\"results_stdout_pattern\")\n        self._results_stdout_pattern: Optional[re.Pattern[str]] = \\\n            re.compile(results_stdout_pattern) if results_stdout_pattern else None\n\n    def _get_env_params(self) -> Dict[str, str]:\n        \"\"\"\n        Get the *shell* environment parameters to be passed to the script.\n\n        Returns\n        -------\n        env_params : Dict[str, str]\n            Parameters to pass as *shell* environment variables into the script.\n            This is usually a subset of `_params` with some possible conversions.\n        \"\"\"\n        rename = {self._RE_INVALID.sub(\"_\", key): key for key in self._shell_env_params}\n        rename.update(self._shell_env_params_rename)\n        return {key_sub: str(self._params[key]) for (key_sub, key) in rename.items()}\n\n    def _extract_stdout_results(self, stdout: str) -> Dict[str, TunableValue]:\n        \"\"\"\n        Extract the results from the stdout of the script.\n\n        Parameters\n        ----------\n        stdout : str\n            The stdout of the script.\n\n        Returns\n        -------\n        results : Dict[str, TunableValue]\n            A dictionary of results extracted from the stdout.\n        \"\"\"\n        if not self._results_stdout_pattern:\n            return {}\n        _LOG.debug(\"Extract regex: '%s' from: '%s'\", self._results_stdout_pattern, stdout)\n        return {key: try_parse_val(val) for (key, val) in self._results_stdout_pattern.findall(stdout)}\n", "path": "mlos_bench/mlos_bench/environments/script_env.py"}]}