Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:2akouwu Reverify run sandboxed

From Leeroopedia
Knowledge Sources
Domains Sandboxing, Native_Execution
Last Updated 2026-10-24 12:00 GMT

Overview

Concrete tool for running untrusted native code under platform confinement (POSIX rlimits / Windows Job Object), never raising for the child, provided by the Reverify library.

Description

The run_sandboxed function is the single entry point for all native execution in Reverify. It runs argv under the strongest confinement each platform offers: wall-clock timeout with hard kill of the process group, output cap (stdout/stderr truncated at a byte limit), isolated working directory, scrubbed environment (minimal PATH, no inherited secrets), stdin from /dev/null. On POSIX it sets rlimits (CPU, address space, file size, NPROC) via a pre-exec hook and gives the child its own session. On Windows it uses a Job Object (best-effort) to cap memory and kill the whole job on close. Fails closed: a timeout, flood, or spawn failure is reported, not raised.

Usage

Import this function when you need to:

  • Run compiled candidate code for functions_equiv_verify or behavioral_equiv.
  • Execute any untrusted native program with resource limits.

Code Reference

Source Location

  • Repository: Reverify
  • File: reverify/sandbox.py
  • Lines: SandboxLimits at L49-58; SandboxResult dataclass; run_sandboxed at L252-322

Signature

@dataclass
class SandboxLimits:
    wall_seconds: float = 10.0
    cpu_seconds: Optional[int] = 5
    memory_bytes: Optional[int] = 512 * 1024 * 1024
    file_size_bytes: Optional[int] = 16 * 1024 * 1024
    max_processes: Optional[int] = 64
    output_bytes: int = 4 * 1024 * 1024

@dataclass
class SandboxResult:
    returncode: Optional[int]
    stdout: bytes
    stderr: bytes
    timed_out: bool
    output_truncated: bool
    killed: bool
    reason: str

    @property
    def ok(self) -> bool:
        """returncode 0 and not timed_out/killed."""

def run_sandboxed(
    argv: Sequence[str],
    *,
    cwd: Optional[str] = None,
    input_bytes: Optional[bytes] = None,
    limits: Optional[SandboxLimits] = None,
    extra_env: Optional[Dict[str, str]] = None,
) -> SandboxResult:
    """Run argv under platform confinement; never raises for the child."""

Import

from reverify.sandbox import run_sandboxed, SandboxLimits, SandboxResult

I/O Contract

Inputs

Name Type Required Description
argv Sequence[str] Yes Command + args
cwd str No Isolated working directory
input_bytes bytes No Stdin bytes (default: /dev/null)
limits SandboxLimits No Resource ceilings (default: SandboxLimits())
extra_env Dict[str, str] No Minimal env additions

Outputs

Name Type Description
return SandboxResult returncode, stdout, stderr, timed_out, output_truncated, killed, reason

Usage Examples

Run a Program

from reverify.sandbox import run_sandboxed, SandboxLimits

result = run_sandboxed(["./candidate", "3", "5"],
                       limits=SandboxLimits(wall_seconds=5, memory_bytes=256*1024*1024))
if result.ok:
    print(result.stdout.decode().strip())
else:
    print(f"Failed: {result.reason}")

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment