GPT LangChain experimental agent - allow dangerous code

**题意:**GPT LangChain 实验性代理 - 允许危险代码

问题背景:

I'm creating a chatbot in VS Code where it will receive csv file through a prompt on Streamlit interface. However from the moment that file is loaded, it is showing a message with the following content:

ValueError: This agent relies on access to a python repl tool which can execute arbitrary code. This can be dangerous and requires a specially sandboxed environment to be safely used. Please read the security notice in the doc-string of this function. You must opt-in to use this functionality by setting allow_dangerous_code=True.For general security guidelines, please see: Security | 🦜️🔗 LangChain

Traceback

python 复制代码
File "c:\Users\  \langchain-ask-csv\.venv\Lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 589, in _run_script
    exec(code, module.__dict__)
File "C:\Users\ \langchain-ask-csv\main.py", line 46, in <module>
    main()
File "C:\Users\  \langchain-ask-csv\main.py", line 35, in main
    agent = create_csv_agent( OpenAI(), csv_file, verbose=True)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\
\langchain-ask-csv\.venv\Lib\site-packages\langchain_experimental\agents\agent_toolkits\csv\base.py", line 66, in create_csv_agent
    return create_pandas_dataframe_agent(llm, df, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\ T\langchain-ask-csv\.venv\Lib\site-packages\langchain_experimental\agents\agent_toolkits\pandas\base.py", line 248, in create_pandas_dataframe_agent
    raise ValueError(

Here's is part of the code where I'm passing the file:

python 复制代码
def main():
    load_dotenv()
    
    # Load the OpenAI API key from the environment variable
    if os.getenv("OPENAI_API_KEY") is None or os.getenv("OPENAI_API_KEY") == "":
        print("OPENAI_API_KEY is not set")
        exit(1)
    else:
        print("OPENAI_API_KEY is set")

    st.set_page_config(page_title="Ask your CSV")
    st.header("Ask your CSV 📈")

    csv_file = st.file_uploader("Upload a CSV file", type="csv")
    if csv_file is not None:

        agent = create_csv_agent( OpenAI(), csv_file, verbose=True)

        user_question = st.text_input("Ask a question about your CSV: ")
        
        if user_question is not None and user_question != "":
            with st.spinner(text="In progress..."):
                st.write(agent.run(user_question))
      

if __name__ == "__main__":
    main()

I checked the link given as suggestion and also tried to search on similar reports but haven't had success.

What might be wrong and how to fix it?

问题解决:

The referenced security notice is in langchain_experimental.agents.agent_toolkits.pandas.base.create_pandas_dataframe_agent --- 🦜🔗 LangChain 0.2.8.

Just do what the message tells you. Do a security analysis, create a sandbox environment for your thing to run in, and then add allow_dangerous_code=True to the arguments you pass to create_csv_agent, which just forwards the argument to create_pandas_dataframe_agent and run it in the sandbox.

相关推荐
a9511416423 分钟前
golang如何设计分布式ID生成系统_golang分布式ID生成系统设计指南
jvm·数据库·python
2301_782659183 分钟前
Go 中高效过滤结构体切片:基于用户名映射去重的最优实践
jvm·数据库·python
2301_813599553 分钟前
Golang怎么处理HTTP响应_Golang HTTP响应处理教程【对比】
jvm·数据库·python
m0_748839495 分钟前
C#怎么将集合分块处理_C#如何使用Chunk方法【实战】
jvm·数据库·python
21439655 分钟前
Bootstrap制作后台管理系统布局 Bootstrap如何搭建Dashboard框架
jvm·数据库·python
xixixi777776 分钟前
AI驱动安全变革:Axios零交互劫持云元数据+CVE-2026-40175,Claude Mythos加速至小时级,攻防不对称重构安全架构
人工智能·5g·ai·claude·攻击·多模态·安全架构
吕源林7 分钟前
Python爬虫怎么获取动态AJAX数据_从浏览器网络控制台分析接口
jvm·数据库·python
AI 赋能10 分钟前
Claude Code for VS Code 使用手册
vscode·claude
m0_6403093011 分钟前
C#怎么实现单例模式 C#如何正确实现线程安全的Singleton单例设计模式【设计模式】
jvm·数据库·python
小江的记录本11 分钟前
【 AI工程化】AI工程化:MLOps、大模型全生命周期管理、大模型安全(幻觉、Prompt注入、数据泄露、合规)
java·人工智能·后端·python·机器学习·ai·架构