Skip to content

[FEATURE]: REPL tool for isolated language-specific code execution separate from bash #20488

Closed

Description

@borealBytes

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Problem

OpenCode routes all code execution through the bash tool. When an agent wants to run a Python snippet, a Node.js expression, or a quick SQL query, it must:

  1. Invoke bash with a full shell invocation (python3 -c "..." or node -e "...")
  2. Handle shell escaping of the code content (single quotes, newlines, special chars)
  3. Mix Python/JS exit codes with shell exit codes indistinguishably
  4. Use DangerFullAccess permission even for trivial read-only calculations

claw-code implements a REPL tool that accepts a code string and language field, runs the code in an isolated subprocess, and returns structured stdout, stderr, and exit_code — cleanly separated from shell semantics.

Proposed solution

// packages/opencode/src/tool/repl.ts

export const REPLTool = Tool.define({
  name: "REPL",
  description: "Execute a code snippet in a language-specific subprocess. Prefer this over bash for Python, JavaScript, or SQL snippets to avoid shell-escaping issues and get clean per-language exit codes.",
  parameters: z.object({
    code: z.string(),
    language: z.enum(["python", "javascript", "typescript", "sql", "ruby", "shell"]),
    timeout_ms: z.number().int().min(1).max(60_000).optional()
  }),
  execute: async ({ code, language, timeout_ms }) => {
    const result = await executeREPL(code, language, timeout_ms ?? 10_000)
    return {
      language,
      stdout: result.stdout,
      stderr: result.stderr,
      exit_code: result.exitCode,
      duration_ms: result.durationMs
    }
  }
})

Language dispatch

Language Subprocess
python python3 -c <code> (or via stdin pipe for multiline)
javascript node --input-type=module
typescript bun run --smol - (stdin)
sql Configurable: sqlite3, duckdb, or psql
shell Direct subprocess (same as bash but with cleaner I/O isolation)

Why this matters

  • Eliminates shell-escaping bugs that cause agents to corrupt code containing quotes, backslashes, or newlines when passed through bash -c
  • Produces clean, parseable stdout/stderr/exit_code without shell wrapper noise
  • Particularly valuable for data science workflows running Python analysis snippets (DuckDB, pandas) inline without writing a temp file
  • Permission model can be more nuanced: a python REPL that only does computation could be ReadOnly; only REPLs with filesystem access need WorkspaceWrite

Acceptance criteria

  • REPL tool executes code in an isolated subprocess with configurable timeout
  • stdout, stderr, and exit_code are returned as separate fields (not concatenated)
  • Multiline code strings are handled without shell-escaping issues (passed via stdin pipe, not -c argument)
  • timeout_ms kills the subprocess cleanly and returns a timeout error in stderr
  • At minimum python and javascript/typescript are supported on first release; additional languages are additive

Related / cross-reference

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 1, 2026
  2. rekram1-node commented on Apr 1, 2026

    @rekram1-node
    Contributor

    closing due to issue spam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions