plimsoll home · All integrations

plimsoll in LangChain

PlimsollCodeTool gives a LangChain or LangGraph agent one tool, plimsoll_run_code, that runs the model's Python or JavaScript in a fresh plimsoll sandbox and tells the model whether the code ran, failed, or was refused before it could run.

LangChain: an open-source framework for building agents on language models. A LangChain tool is also a LangGraph tool, so LangChain's create_agent, LangGraph's ToolNode and graphs of your own all call it the same way. LangChain (EXTERNAL · official docs ↗)

The Professor (a fictional narrator)

LangChain links the steps, LangGraph draws the map, and plimsoll keeps the code in a room it cannot leave. Somebody had to take the job with no windows.

Real quote

Donald E. Knuth: “Beware of bugs in the above code; I have only proved it correct, not tried it.”

the last sentence of a 1977 memo to Peter van Emde Boas, as Knuth tells it on his own FAQ page. Knuth's FAQ (EXTERNAL · author's page ↗)

Wire it up

pip install 'plimsoll-client[langchain]' langchain
from langchain.agents import create_agent
from plimsoll_client import Client
from plimsoll_client.execution import CodeExecutor
from plimsoll_client.langchain import PlimsollCodeTool

executor = CodeExecutor(Client("https://plimsoll.internal:8746", token=TOKEN))
agent = create_agent(model, tools=[PlimsollCodeTool(executor)])

Options, limits and errors: Python client guide, LangChain tool and Deep Agents backend (EXTERNAL · source repo ↗)

Follow one call

Replay a recorded scenario. The diagram lights each hop the call passes; a refused call stops where it is refused. These buttons send no execution requests. Each answer's source states how it was recorded, including any fixture used. Exception panels show what reached the application, rather than an invented code result.

The modelasks for plimsoll_run_codeSTOPPED HEREMAY HAVE RUNThe language model decides to run code and writes the arguments: the code, its language and any input files.LangChaintool.invokeSTOPPED HEREMAY HAVE RUNLangChain checks the model's arguments against the tool's args_schema (the language list included) and calls the tool; a call that does not fit stops here. LangGraph's ToolNode calls the tool through the same method.PlimsollCodeToolplimsoll_run_codeSTOPPED HEREMAY HAVE RUNChecks the arguments, hands them to the executor, and turns whatever comes back into the JSON the model reads: ran true, false or "unknown".CodeExecutorchecks, then sendsSTOPPED HEREMAY HAVE RUNAsks the daemon what it is, refuses if its isolation tier is below the floor or it lacks the language, then sends the code and files as one fresh project with a fixed command.plimsolldadmits or refusesSTOPPED HEREMAY HAVE RUNChecks the floor again against its current evidence, admits the run if it has capacity, and states a run record of exactly what it ran and answered.Fresh sandboxruns, then is deletedSTOPPED HEREMAY HAVE RUNA new locked-down container with no network: the files are written, the code runs once, and the container is removed.The modelasks for plimsoll_run_codeSTOP?The language model decides to run code and writes the arguments: the code, its language and any input files.LangChaintool.invokeSTOP?LangChain checks the model's arguments against the tool's args_schema (the language list included) and calls the tool; a call that does not fit stops here. LangGraph's ToolNode calls the tool through the same method.PlimsollCodeToolplimsoll_run_codeSTOP?Checks the arguments, hands them to the executor, and turns whatever comes back into the JSON the model reads: ran true, false or "unknown".CodeExecutorchecks, then sendsSTOP?Asks the daemon what it is, refuses if its isolation tier is below the floor or it lacks the language, then sends the code and files as one fresh project with a fixed command.plimsolldadmits or refusesSTOP?Checks the floor again against its current evidence, admits the run if it has capacity, and states a run record of exactly what it ran and answered.Fresh sandboxruns, then is deletedSTOP?A new locked-down container with no network: the files are written, the code runs once, and the container is removed.

The model asks for

The tool answers the model

The Professor (a fictional narrator)

Each step of the call

  1. The model: The language model decides to run code and writes the arguments: the code, its language and any input files.
  2. LangChain: LangChain checks the model's arguments against the tool's args_schema (the language list included) and calls the tool; a call that does not fit stops here. LangGraph's ToolNode calls the tool through the same method.
  3. PlimsollCodeTool: Checks the arguments, hands them to the executor, and turns whatever comes back into the JSON the model reads: ran true, false or "unknown".
  4. CodeExecutor: Asks the daemon what it is, refuses if its isolation tier is below the floor or it lacks the language, then sends the code and files as one fresh project with a fixed command.
  5. plimsolld: Checks the floor again against its current evidence, admits the run if it has capacity, and states a run record of exactly what it ran and answered.
  6. Fresh sandbox: A new locked-down container with no network: the files are written, the code runs once, and the container is removed.

How thick should the walls be?

The executor carries a floor; the daemon states its isolation tier. This picker is a teaching simulation: change either to see whether the tier meets the floor. It sends no request and does not check other capabilities.

The Professor (a fictional narrator)

The executor's floor defaults to kernel: docker under runc is the container tier and refuses every call until it runs gVisor, or the executor is built with an explicit container floor, which is for development on your own code only. Use the spelling shown in this page's wiring example.

Surprises and limits

One tool for LangChain and LangGraphPlimsollCodeTool is a LangChain BaseTool, so LangChain's create_agent, LangGraph's ToolNode and a graph of your own call it the same way, with invoke or ainvoke. The extra installs only langchain-core; create_agent comes with the langchain package.
The default floor refuses plain DockerCodeExecutor's floor is kernel. A daemon on docker under runc is the container tier and refuses every call until it runs gVisor, or until the executor is built with minimum_isolation="container", which is for development on your own code only.
Nothing persists between callsEvery call is a fresh sandbox: no variable, import or file from an earlier call is there, and the tool's description says so. An agent that needs files and a shell kept from one command to the next wants plimsoll's Deep Agents backend instead, which serves one session for the agent's whole run.
The answer is the JSON textThe tool answers with its JSON as the ToolMessage's content, which already carries the run record's digest. It refuses a response_format other than "content", so the answer always reaches the model whole.
Cancelling ainvoke cancels the callainvoke runs the call in a worker thread with a cancel handle that is cancelled with the await. Cancelled before the run request is sent (while the daemon is still answering Describe, say), the call never sends it. Cancelled while the run is in flight, its connection is cut and the thread ends at once. The code may have run by then; the daemon stops it only if its provider honors the closed connection.