Copy
---
title: Python REPL
---
때로는 복잡한 계산의 경우, LLM이 답을 직접 생성하도록 하는 것보다 LLM이 답을 계산하는 코드를 생성하도록 한 다음, 그 코드를 실행하여 답을 얻는 것이 더 나을 수 있습니다. 이를 쉽게 수행하기 위해 명령을 실행할 수 있는 간단한 Python REPL을 제공합니다.
이 인터페이스는 출력된 내용만 반환합니다. 따라서 답을 계산하는 데 사용하려면 반드시 답을 출력하도록 해야 합니다.
<Warning>
**Python REPL은 호스트 머신에서 임의의 코드를 실행할 수 있습니다(예: 파일 삭제, 네트워크 요청). 주의해서 사용하세요.**
</Warning>
```python
from langchain.tools import Tool
from langchain_experimental.utilities import PythonREPL
Copy
python_repl = PythonREPL()
Copy
python_repl.run("print(1+1)")
Copy
Python REPL can execute arbitrary code. Use with caution.
Copy
'2\n'
Copy
# You can create the tool to pass to an agent
repl_tool = Tool(
name="python_repl",
description="A Python shell. Use this to execute python commands. Input should be a valid python command. If you want to see the output of a value, you should print it out with `print(...)`.",
func=python_repl.run,
)
Copy
---
<Callout icon="pen-to-square" iconType="regular">
[Edit the source of this page on GitHub.](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/tools/python.mdx)
</Callout>
<Tip icon="terminal" iconType="regular">
[Connect these docs programmatically](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
</Tip>