🌐
Medium
medium.com › data-science-in-your-pocket › building-code-execution-agents-in-generative-ai-using-langchain-04c933492213
Building Code Execution Agents in Generative AI using LangChain | by Mehul Gupta | Data Science in Your Pocket | Medium
October 3, 2024 - from langchain.agents import AgentExecutor, initialize_agent from langchain.memory import ConversationBufferMemory from langchain.tools import BaseTool, StructuredTool, tool from langchain.agents.agent_types import AgentType import subprocess @tool def generate_code(query: str)->str: "Generate codes for a given problem" result = llm("Write a code snippet in Python for the given Problem.
🌐
Langchain
docs.langchain.com › oss › python › langchain › tools
Tools - Docs by LangChain
Join us May 13th & May 14th at Interrupt, the Agent Conference by LangChain. Buy tickets > ... Tools extend what agents can do—letting them fetch real-time data, execute code, query external databases, and take actions in the world. Under the hood, tools are callable functions with well-defined inputs and outputs that get passed to a chat model.
Discussions

Can langchain run an existing script in Python that I wrote and give me the result ?
Write a tool that call the script and you are good to go. Check out agents and custom tools More on reddit.com
🌐 r/LangChain
5
3
August 7, 2023
How can I safely execute code generated by an LLM?
The way I did this was to set up a docker container that runs python and contains an API. I created a custom tool that called the API. The input to the tool was a simple list of two strings - first one was the libraries that would go in the requirements.txt file, the second was the code itself. Kept things simple enough for the llm to actually use the tool. The tool takes this list and creates a payload to send a post request to the API. The API takes the payload and creates a requirements.txt file and a python file and then runs the python file, captures the output, and returns the output in the response. More on reddit.com
🌐 r/LangChain
12
8
July 16, 2023
How to deploy Langchain python script to production
Hot take: if you’ve never deployed a single python script into production before, you should start by learning basics of python and the classic libraries like flask, fastapi, etc before jumping into langchain More on reddit.com
🌐 r/LangChain
23
10
June 10, 2023
use some python package for python agent
Yes, it’s very possible with custom tools https://python.langchain.com/docs/modules/agents/tools/custom_tools#subclassing-the-basetool . You can basically just create a class that defines the behavior of the tool and is just a function that uses the library that you wish to incorporate More on reddit.com
🌐 r/LangChain
4
3
November 26, 2023
🌐
Better Programming
betterprogramming.pub › building-a-custom-langchain-tool-for-generating-executing-code-fa20a3c89cfd
Build a Custom Langchain Tool for Generating and Executing Code | by Paolo Rechia | Better Programming
May 18, 2023 - I wanted to have something similar to Langchain Python REPL, but that instead: Allowed the generated source code to be saved in a file. Allowed the agent to install pip packages. Allowed execution of the source code, with the full output/traceback · Allowed linters to be applied and different code generations sampled accordingly. Offered the option to delegate the code generation completely to the tool, so the main agent does not have to be necessarily good at coding (though the model used in code still has to be good at coding).
🌐
LangChain
blog.langchain.com › code-execution-with-langgraph
LangGraph for Code Generation
March 1, 2024 - We implement LangSmith custom evaluators for both (1) import evaluation and (2) code execution. We run evaluation on context stuffing with our 20 question eval set four times. Here is our eval result. With context stuffing we see ~98% of the import tests are correct and ~55% of the code execution tests (N=79 successful trials).
🌐
GitHub
github.com › langchain-ai › open-swe
GitHub - langchain-ai/open-swe: An Open-Source Asynchronous Coding Agent · GitHub
1 week ago - An Open-Source Asynchronous Coding Agent. Contribute to langchain-ai/open-swe development by creating an account on GitHub.
Starred by 8.8K users
Forked by 1K users
Languages   Python
🌐
GitHub
github.com › dtunai › cpp-langchain
GitHub - dtunai/cpp-langchain: Tool for executing C/C++ code snippets with Langchain Agents. · GitHub
This package provides an integrated tool for generating and executing C/C++ code snippets externally in Langchain. Allows Langchain users to specify the desired C++ standard version and set optional CPU time limits for code execution.
Author   dtunai
🌐
GitHub
github.com › junfanz1 › Code-Interpreter-ReAct-LangChain-Agent
GitHub - junfanz1/Code-Interpreter-ReAct-LangChain-Agent: This project combines two functionalities: a Code Interpreter using LLM Agent Orchestration and Tool Utilization, and a ReAct LangChain Agent example.ReAct agent using LangChain, integrated with a custom tool to calculate the length of a given text. It serves as a foundational example for building more complex, tool-augmented LLM applications. · GitHub
This project combines two functionalities: a Code Interpreter using LLM Agent Orchestration and Tool Utilization, and a ReAct LangChain Agent example. Engineered an autonomous multi-agent system by integrating Code Interpreter, ReAct, and LangChain frameworks, which streamlined dynamic code execution and reasoning, resulting in a 35% boost in operational efficiency.
Author   junfanz1
Find elsewhere
🌐
LangChain
changelog.langchain.com › announcements › langchain-sandbox-run-untrusted-python-in-your-ai-agents
LangChain - Changelog | LangChain Sandbox: Run untrusted Python in
May 29, 2025 - LangChain Sandbox lets you safely run untrusted Python in your AI agents! Built on Pyodide (Python in WebAssembly), LangChain Sandbox lets you execute code...
🌐
Hopx
hopx.ai › home › blog › tutorials › langchain tools with secure code execution using hopx
LangChain Tools with Secure Code Execution Using HopX
November 26, 2025 - Learn how to build LangChain agents that execute code safely in isolated sandboxes. Complete tutorial with custom tools, PythonREPL replacement, and production-ready patterns.
🌐
E2B
e2b.dev › blog › build-langchain-agent-with-code-interpreter
Build LangChain agent with code interpreter — E2B Blog
June 13, 2024 - Now we define the format_to_tool_messages function to identify for each agent's action whether it corresponds to a specific tool. If it does, the function formats the action and observation into messages and appends them to the messages list, ensuring no duplicates. We create a prompt template that will be used by the agent to generate responses. We define and invoke the agent, during which we specify the prompt, which is to plot and show sinus. from typing import List, Sequence, Tuple from langchain_core.prompts import ChatPromptTemplate from langchain.agents import AgentExecutor from langcha
🌐
LangChain
blog.langchain.com › code-interpreter-api
Code Interpreter API
July 16, 2023 - The core of this project is a LangChain Agent, specifically the new OpenAIFunctionsAgent which gives the advantage of calling functions/tools to better handle the user needs. For the code interpreter, we need to give it access to a Python interpreter so it can execute Python code.
🌐
LangChain
blog.langchain.com › execute-code-with-sandboxes-for-deepagents
Execute Code with Sandboxes for Deep Agents
November 13, 2025 - By Vivek Trivedy Today we're excited to launch Sandboxes for Deep Agents, a new set of integrations that allow you to safely execute arbitrary Deep Agent code in remote sandboxes.
🌐
Ryz Labs Learn
learn.ryzlabs.com › home › ai coding assistants › how to use langchain for advanced code generation in 2 hours
How to Use LangChain for Advanced Code Generation in 2 Hours | Ryz Labs | Ryz Labs Learn
1 week ago - import unittest def test_generated_code(code: str): exec_globals = {} exec(code, exec_globals) assert exec_globals['factorial'](5) == 120 if __name__ == "__main__": # Generate code and test it user_prompt = "Write a Python function to calculate the factorial of a number." generated_code = generate_code(user_prompt) test_generated_code(generated_code) API Key Issues: Ensure your OpenAI API key is correctly set in your environment variables. Installation Errors: Verify that you have installed the correct versions of LangChain and OpenAI libraries. Execution Errors: If the generated code fails, check the prompt for clarity and specificity.
🌐
GitHub
github.com › langchain-ai › langchain-sandbox
GitHub - langchain-ai/langchain-sandbox: Safely run untrusted Python code using Pyodide and Deno · GitHub
January 14, 2026 - A secure environment for running Python code using Pyodide (WebAssembly) and Deno · LangChain Sandbox provides a secure environment for executing untrusted Python code.
Starred by 238 users
Forked by 27 users
Languages   Python 67.9% | TypeScript 28.2% | Makefile 3.9%