Code execution
SandboxPolicy
Section titled “SandboxPolicy”OS-level sandbox applied to the code-execution subprocess on Linux/macOS.
Pass to CodeExecutionConfig(sandbox_policy=...) to enable the sandbox;
omit (or pass None) to disable it. See the sandbox reference for the
layered defenses: env scrub, namespaces, Landlock FS allowlist, rlimits,
seccomp deny-list, and optional cgroup v2 on Linux.
max_memory_mb: per-session memory cap (default 2048).max_cpu_secs: per-session CPU time cap (default 300).max_procs: per-session process/thread cap (default 64).max_open_fds: per-session open-fd cap (default 1024).max_file_sz_mb: per-session max written-file size (default 256).network:NetworkMode.NoNetwork,.Loopback, or.Full.extra_fs_read: additional paths the sandboxed process may read.extra_fs_write: additional paths the sandboxed process may read/write.extra_env: additional environment variable names allowed through.strict: fail initialization if requested filesystem or network isolation is unavailable.
SandboxPolicy.__init__
Section titled “SandboxPolicy.__init__”__init__( max_memory_mb: int = 2048, max_cpu_secs: int = 300, max_procs: int = 64, max_open_fds: int = 1024, max_file_sz_mb: int = 256, network: NetworkMode = NetworkMode.Loopback, extra_fs_read: list[str] = [], extra_fs_write: list[str] = [], extra_env: list[str] = [], strict: bool = False,) -> NoneCodeExecutionConfig
Section titled “CodeExecutionConfig”Configuration for the built-in Python code execution tool.
Pass to Runner(code_execution_config=...) to enable the execute_python
tool. Per-request, set ChatCompletionRequest.enable_code_execution=True.
All fields are optional:
python_path: interpreter to run. Defaults topythonon Windows,python3elsewhere.timeout_secs: per-call timeout. Defaults to 30.working_directory: shared working directory. Defaults to a per-session temp directory.sandbox_policy: an OS-level sandbox to apply to the spawned interpreter on Linux/macOS.None(default) disables the sandbox; passing aSandboxPolicyenables it with the configured limits.permission:CodeExecutionPermission.Auto,.Ask, or.Deny. For new code, preferChatCompletionRequest.agent_permission.approval_callback: code-execution-specific callback. For new code, preferChatCompletionRequest.agent_approval_callback, which applies to all agent actions.
CodeExecutionConfig.__init__
Section titled “CodeExecutionConfig.__init__”__init__( python_path: str | None = None, timeout_secs: int | None = None, working_directory: str | None = None, sandbox_policy: SandboxPolicy | None = None, permission: CodeExecutionPermission | None = None, approval_callback: Callable[[dict[str, object]], bool] | None = None,) -> NoneGenerated from mistralrs-pyo3/mistralrs.pyi.