Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion nbs/00_core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,9 @@
"class RunPython:\n",
" \"\"\"Execute Python with audit-hook safety checks and access to LLM tools, returning last expression.\n",
" `import` works in the usual way. All builtins are available.\n",
" Multiline code blocks can be used, including defining functions and variables.\n",
" Multiline code blocks can be used. By default, defining functions or classes is *not* allowed (`ban_defs=True`); construct `RunPython` with `ban_defs=False` to permit them.\n",
"\n",
" **Sandbox**: an audit hook blocks risky operations by default (e.g. network), and `socket`/`importlib` imports are banned. To permit one, the user must `allow()` a function that performs it from the real Python process; sandboxed code cannot `allow()` itself.\n",
" **NB**: Locals are exported back to the caller's namespace.\"\"\"\n",
"\n",
" def __init__(self, g=None, sentinel=None, ok_dests=UNSET, ban_imports=frozenset({'socket','importlib'}), ban_defs=True,\n",
Expand Down
4 changes: 3 additions & 1 deletion safepyrun/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ def _find_perm_err(e):
class RunPython:
"""Execute Python with audit-hook safety checks and access to LLM tools, returning last expression.
`import` works in the usual way. All builtins are available.
Multiline code blocks can be used, including defining functions and variables.
Multiline code blocks can be used. By default, defining functions or classes is *not* allowed (`ban_defs=True`); construct `RunPython` with `ban_defs=False` to permit them.

**Sandbox**: an audit hook blocks risky operations by default (e.g. network), and `socket`/`importlib` imports are banned. To permit one, the user must `allow()` a function that performs it from the real Python process; sandboxed code cannot `allow()` itself.
**NB**: Locals are exported back to the caller's namespace."""

def __init__(self, g=None, sentinel=None, ok_dests=UNSET, ban_imports=frozenset({'socket','importlib'}), ban_defs=True,
Expand Down