An open API service indexing awesome lists of open source software.

https://github.com/a14a-org/langchain-omnirun

LangChain integration for OmniRun sandboxes — execute code in isolated Firecracker microVMs
https://github.com/a14a-org/langchain-omnirun

ai-agents code-execution firecracker langchain microvm python sandbox

Last synced: 9 days ago
JSON representation

LangChain integration for OmniRun sandboxes — execute code in isolated Firecracker microVMs

Awesome Lists containing this project

README

          

# langchain-omnirun

LangChain integration for [OmniRun](https://omnirun.dev) sandboxes. Execute code in isolated Firecracker microVMs from your LangChain agents.

Each sandbox runs its own Linux kernel with hardware-level isolation, making it safe to execute untrusted code generated by LLMs.

## Installation

```bash
pip install langchain-omnirun
```

## Quick start

```python
from langchain_omnirun import OmniRunToolkit

toolkit = OmniRunToolkit()
tools = toolkit.get_tools()

# Execute Python code
result = tools[0].invoke({"code": "print(sum(range(100)))"})
print(result) # 4950

toolkit.cleanup()
```

## Available tools

The toolkit provides three tools that share a single sandbox instance:

| Tool | Name | Description |
|------|------|-------------|
| `OmniRunSandboxTool` | `omnirun_execute` | Execute Python code in an isolated Firecracker microVM |
| `OmniRunFilesTool` | `omnirun_files` | Read or write files in the sandbox |
| `OmniRunShellTool` | `omnirun_shell` | Run shell commands (install packages, list files, etc.) |

## Using with a LangChain agent

```python
from langchain_openai import ChatOpenAI
from langchain.agents import create_tool_calling_agent, AgentExecutor
from langchain_core.prompts import ChatPromptTemplate
from langchain_omnirun import OmniRunToolkit

toolkit = OmniRunToolkit()
tools = toolkit.get_tools()

llm = ChatOpenAI(model="gpt-4o")
prompt = ChatPromptTemplate.from_messages([
("system", "You are a helpful coding assistant with access to a sandbox."),
("human", "{input}"),
("placeholder", "{agent_scratchpad}"),
])

agent = create_tool_calling_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools)

result = executor.invoke({
"input": "Write a Python script that calculates the first 20 Fibonacci numbers, save it to /tmp/fib.py, then run it."
})
print(result["output"])

toolkit.cleanup()
```

## Configuration

```python
# Custom template and timeout
toolkit = OmniRunToolkit(
template="python-3.11", # Sandbox template
timeout=60, # Per-execution timeout in seconds
)
```

## Environment variables

- `OMNIRUN_API_KEY` - Your OmniRun API key (required)

## Documentation

- [OmniRun docs](https://docs.omnirun.dev)
- [LangChain docs](https://python.langchain.com)

## License

MIT