Skip to content

feat: Safe code execution sandbox for model-generated code #471

Description

@rexlunae

Inspiration: Unsloth

Unsloth Studio lets models run Bash and Python (not just JavaScript) in a sandbox, similar to Claude Artifacts. This lets models test code, generate files, and verify answers with real computation — making outputs more reliable.

Unsloth also connects to provider-side sandboxes (OpenAI's code interpreter, Anthropic's code execution tool) when using cloud models.

Current RustyClaw state

RustyClaw has:

  • execute_command / exec tool — general shell execution (potentially dangerous)
  • Sandbox support (Bubblewrap, Landlock, sandbox-exec) — but configured at the exec level
  • No dedicated "safe code execution" tool optimized for model-generated code

What RustyClaw could do

Add a code_exec tool specifically designed for running model-generated code safely:

  1. Language auto-detection: Detects code blocks (python, bash) and routes to the right runtime
  2. Sandbox by default: Runs in bubblewrap/landlock with no filesystem access except a temp dir
  3. Resource limits: CPU time, memory, wall-clock timeout per execution
  4. Output capture: stdout, stderr, exit code, any generated files
  5. Persistent workspace: Option to keep files between calls (like a Jupyter notebook)
  6. Package allowlist: Optionally allow pip/npm install from a curated list
  7. Network disabled by default: Can be toggled for specific use cases

Why this matters

Agents frequently generate code to solve problems. The current exec tool is powerful but scary — it can do anything. A dedicated code_exec tool with sensible defaults would let agents use code execution freely without risking the host.

Scope

  • rustyclaw-core: code_exec tool implementation
  • Reuses existing sandbox infrastructure (Bubblewrap/Landlock)
  • Python runtime detection (system python or uv-managed venv)
  • Configurable: allowed languages, resource limits, network policy

Prior art

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions