sergiopaniego HF Staff commited on
Commit
32e7811
·
verified ·
1 Parent(s): f739a51

Authorize heapq, bisect, operator and cmath; make the env constructor accept them

Browse files
envs/coding_env/server/app.py CHANGED
@@ -21,6 +21,7 @@ Usage:
21
  python -m envs.coding_env.server.app
22
  """
23
 
 
24
  import os
25
  from contextlib import suppress
26
 
@@ -30,7 +31,16 @@ from openenv.core.env_server import create_app
30
 
31
  # Create the app with web interface and README integration
32
  # Pass the class (factory) instead of an instance for WebSocket session support
33
- app = create_app(PythonCodeActEnv, CodeAction, CodeObservation, env_name="coding_env", max_concurrent_envs=512)
 
 
 
 
 
 
 
 
 
34
 
35
 
36
  def main():
 
21
  python -m envs.coding_env.server.app
22
  """
23
 
24
+ import functools
25
  import os
26
  from contextlib import suppress
27
 
 
31
 
32
  # Create the app with web interface and README integration
33
  # Pass the class (factory) instead of an instance for WebSocket session support
34
+ # MBPP reference solutions need these four, and smolagents' default allowlist has none of
35
+ # them: without this, 8 of the 170 sanitized training problems are unsolvable whatever the
36
+ # model writes. `sys` is deliberately left out of a sandbox that runs model-written code.
37
+ app = create_app(
38
+ functools.partial(PythonCodeActEnv, additional_imports=["heapq", "bisect", "operator", "cmath"]),
39
+ CodeAction,
40
+ CodeObservation,
41
+ env_name="coding_env",
42
+ max_concurrent_envs=512,
43
+ )
44
 
45
 
46
  def main():
envs/coding_env/server/python_codeact_env.py CHANGED
@@ -13,7 +13,7 @@ Python code actions using PyExecutor.
13
 
14
  import uuid
15
 
16
- from openenv.core.env_server.interfaces import Action, Environment, Observation
17
 
18
  from ..models import CodeAction, CodeObservation, CodeState
19
  from .python_executor import PyExecutor
@@ -21,8 +21,6 @@ from .transforms import create_safe_coding_transform
21
 
22
 
23
  class PythonCodeActEnv(Environment):
24
- SUPPORTS_CONCURRENT_SESSIONS = True
25
-
26
  """
27
  Python Code Action Environment for executing code and tracking state.
28
 
@@ -45,11 +43,17 @@ class PythonCodeActEnv(Environment):
45
  >>> print(env.state.last_exit_code) # 0
46
  """
47
 
 
 
48
  def __init__(
49
  self,
 
 
50
  ):
51
- self.transform = create_safe_coding_transform()
52
- self._executor = PyExecutor()
 
 
53
  self._state = CodeState()
54
 
55
  def reset(self) -> Observation:
@@ -65,10 +69,10 @@ class PythonCodeActEnv(Environment):
65
  self._state.last_exit_code = 0
66
 
67
  # Reset executor to clear any previously defined variables/functions
68
- self._executor = PyExecutor()
69
 
70
  # Reset transform to clear any accumulated state
71
- self.transform = create_safe_coding_transform()
72
 
73
  # Return initial observation
74
  observation = CodeObservation(
 
13
 
14
  import uuid
15
 
16
+ from openenv.core.env_server.interfaces import Action, Environment, Observation, Transform
17
 
18
  from ..models import CodeAction, CodeObservation, CodeState
19
  from .python_executor import PyExecutor
 
21
 
22
 
23
  class PythonCodeActEnv(Environment):
 
 
24
  """
25
  Python Code Action Environment for executing code and tracking state.
26
 
 
43
  >>> print(env.state.last_exit_code) # 0
44
  """
45
 
46
+ SUPPORTS_CONCURRENT_SESSIONS = True
47
+
48
  def __init__(
49
  self,
50
+ transform: Transform | None = None,
51
+ additional_imports: list[str] | None = None,
52
  ):
53
+ self._transform = transform
54
+ self._additional_imports = additional_imports
55
+ self.transform = transform or create_safe_coding_transform()
56
+ self._executor = PyExecutor(additional_imports=additional_imports)
57
  self._state = CodeState()
58
 
59
  def reset(self) -> Observation:
 
69
  self._state.last_exit_code = 0
70
 
71
  # Reset executor to clear any previously defined variables/functions
72
+ self._executor = PyExecutor(additional_imports=self._additional_imports)
73
 
74
  # Reset transform to clear any accumulated state
75
+ self.transform = self._transform or create_safe_coding_transform()
76
 
77
  # Return initial observation
78
  observation = CodeObservation(
server/app.py CHANGED
@@ -21,6 +21,7 @@ Usage:
21
  python -m envs.coding_env.server.app
22
  """
23
 
 
24
  import os
25
  from contextlib import suppress
26
 
@@ -30,7 +31,16 @@ from openenv.core.env_server import create_app
30
 
31
  # Create the app with web interface and README integration
32
  # Pass the class (factory) instead of an instance for WebSocket session support
33
- app = create_app(PythonCodeActEnv, CodeAction, CodeObservation, env_name="coding_env", max_concurrent_envs=512)
 
 
 
 
 
 
 
 
 
34
 
35
 
36
  def main():
 
21
  python -m envs.coding_env.server.app
22
  """
23
 
24
+ import functools
25
  import os
26
  from contextlib import suppress
27
 
 
31
 
32
  # Create the app with web interface and README integration
33
  # Pass the class (factory) instead of an instance for WebSocket session support
34
+ # MBPP reference solutions need these four, and smolagents' default allowlist has none of
35
+ # them: without this, 8 of the 170 sanitized training problems are unsolvable whatever the
36
+ # model writes. `sys` is deliberately left out of a sandbox that runs model-written code.
37
+ app = create_app(
38
+ functools.partial(PythonCodeActEnv, additional_imports=["heapq", "bisect", "operator", "cmath"]),
39
+ CodeAction,
40
+ CodeObservation,
41
+ env_name="coding_env",
42
+ max_concurrent_envs=512,
43
+ )
44
 
45
 
46
  def main():
server/python_codeact_env.py CHANGED
@@ -13,7 +13,7 @@ Python code actions using PyExecutor.
13
 
14
  import uuid
15
 
16
- from openenv.core.env_server.interfaces import Action, Environment, Observation
17
 
18
  from ..models import CodeAction, CodeObservation, CodeState
19
  from .python_executor import PyExecutor
@@ -21,8 +21,6 @@ from .transforms import create_safe_coding_transform
21
 
22
 
23
  class PythonCodeActEnv(Environment):
24
- SUPPORTS_CONCURRENT_SESSIONS = True
25
-
26
  """
27
  Python Code Action Environment for executing code and tracking state.
28
 
@@ -45,11 +43,17 @@ class PythonCodeActEnv(Environment):
45
  >>> print(env.state.last_exit_code) # 0
46
  """
47
 
 
 
48
  def __init__(
49
  self,
 
 
50
  ):
51
- self.transform = create_safe_coding_transform()
52
- self._executor = PyExecutor()
 
 
53
  self._state = CodeState()
54
 
55
  def reset(self) -> Observation:
@@ -65,10 +69,10 @@ class PythonCodeActEnv(Environment):
65
  self._state.last_exit_code = 0
66
 
67
  # Reset executor to clear any previously defined variables/functions
68
- self._executor = PyExecutor()
69
 
70
  # Reset transform to clear any accumulated state
71
- self.transform = create_safe_coding_transform()
72
 
73
  # Return initial observation
74
  observation = CodeObservation(
 
13
 
14
  import uuid
15
 
16
+ from openenv.core.env_server.interfaces import Action, Environment, Observation, Transform
17
 
18
  from ..models import CodeAction, CodeObservation, CodeState
19
  from .python_executor import PyExecutor
 
21
 
22
 
23
  class PythonCodeActEnv(Environment):
 
 
24
  """
25
  Python Code Action Environment for executing code and tracking state.
26
 
 
43
  >>> print(env.state.last_exit_code) # 0
44
  """
45
 
46
+ SUPPORTS_CONCURRENT_SESSIONS = True
47
+
48
  def __init__(
49
  self,
50
+ transform: Transform | None = None,
51
+ additional_imports: list[str] | None = None,
52
  ):
53
+ self._transform = transform
54
+ self._additional_imports = additional_imports
55
+ self.transform = transform or create_safe_coding_transform()
56
+ self._executor = PyExecutor(additional_imports=additional_imports)
57
  self._state = CodeState()
58
 
59
  def reset(self) -> Observation:
 
69
  self._state.last_exit_code = 0
70
 
71
  # Reset executor to clear any previously defined variables/functions
72
+ self._executor = PyExecutor(additional_imports=self._additional_imports)
73
 
74
  # Reset transform to clear any accumulated state
75
+ self.transform = self._transform or create_safe_coding_transform()
76
 
77
  # Return initial observation
78
  observation = CodeObservation(