onlinecompiler.io

LangChain tools

The langchain-onlinecompiler package gives LangChain agents two tools: one runs a program in any of 46 languages and reads its output, the other judges code against test cases. Every run is in a fresh sandbox with no network.

Terminal
pip install -U langchain-onlinecompiler
export ONLINECOMPILER_API_KEY="your-api-key"

Get a free API key (type API) from the dashboard, no card needed, and set it as ONLINECOMPILER_API_KEY, or pass api_key="..." to a tool or the toolkit. Then call the tools directly:

tools.py
from langchain_onlinecompiler import OnlineCompilerRunCode, OnlineCompilerRunTests

run_code = OnlineCompilerRunCode()
print(run_code.invoke({"compiler": "python-3.14", "code": "print(2 ** 100)"}))

run_tests = OnlineCompilerRunTests()
print(run_tests.invoke({
    "compiler": "python-3.14",
    "code": "a, b = map(int, input().split())\nprint(a + b)",
    "tests": [
        {"input": "2 3", "expected_output": "5"},
        {"input": "10 4", "expected_output": "14"},
    ],
}))

The first call prints:

Output
status: success
exit_code: 0
time: 0.0309 s
memory: 13296 KB
truncated: false
output:
1267650600228229401496703205376
error: (empty)

In an agent

agent.py
from langchain.agents import create_agent
from langchain_onlinecompiler import OnlineCompilerToolkit

agent = create_agent(
    model="openai:gpt-5-mini",  # any chat model with tool calling
    tools=OnlineCompilerToolkit().get_tools(),
    system_prompt="Run code to check your answers instead of guessing.",
)
result = agent.invoke({"messages": [{"role": "user", "content": "What is the 90th Fibonacci number? Compute it."}]})
print(result["messages"][-1].content)

The tools

  • OnlineCompilerRunCode (tool name onlinecompiler_run_code) takes compiler, code, and optional input and time_limit, and runs the program as /api/run-code-sync/ does: up to 30 seconds and 512 MB, no network.
  • OnlineCompilerRunTests (tool name onlinecompiler_run_tests) takes compiler, code and tests (each an input and an expected_output), with an optional checker (trim, exact, tokens, float, rows, table, table_ordered), and judges as /api/run-tests/ does. Hidden tests show only their verdict.
  • OnlineCompilerToolkit gives both.

Source and issues: github.com/onlinecompiler-io/langchain-onlinecompiler; package: PyPI. It uses the official Python client, which covers the rest of the API. Agents in Claude, ChatGPT, Cursor and VS Code can use the MCP server instead, and Node.js apps the Vercel AI SDK tools.

Questions

Which LangChain versions does it work with?
langchain-core 1.0 and later, on Python 3.11 and later. The tools are ordinary LangChain tools, so create_agent, LangGraph's ToolNode and anything else that takes tools accept them.
What does the model see, and what does my code get?
The model gets a short text result: status, exit code, time, memory and the output and errors, or for run tests the verdict, score and each test's verdict. The full JSON result comes back as the tool message's artifact for your own code.
How many runs does it use?
Each run code call is one run, and each test in a run tests call is one run, from your API key's allowance. The Free plan has 100,000 runs a month.
What happens when the key is wrong or a limit is reached?
A refused key raises AuthenticationError, so you see it rather than the model. A limit reached, a bad request or a network error goes back to the model as an error message it can read.