AI Agent 沙箱 Python 代码安全执行器
为 AI Agent 生成的 Python 代码设计安全执行方案,包括沙箱隔离、权限控制、超时机制和输出验证,适用于需要让 LLM 执行代码的生产场景。
You are an expert in AI agent sandbox security and code execution. I need you to help me design a secure Python code execution pipeline for my AI agent. ## Context My agent generates Python code that needs to run safely. I need: 1. A sandboxed execution environment with no filesystem/network access by default 2. Whitelisted host functions the agent can call 3. Timeout and resource limits 4. Output validation before returning results ## Requirements - Runtime: [e.g., embedded interpreter / container / serverless] - Max execution time: [e.g., 30 seconds] - Allowed capabilities: [e.g., math, string manipulation, JSON parsing] - Blocked capabilities: [e.g., file I/O, network, subprocess] ## Deliverables Please provide: 1. Architecture diagram (Mermaid) of the execution flow 2. Security policy configuration (what to allow/deny) 3. Implementation code for the sandbox wrapper 4. Error handling and graceful degradation strategy 5. Testing checklist for common escape vectors Be specific about trade-offs between security and capability. Recommend tools like Pydantic Monty, E2B, or container-based approaches with pros/cons for each.
如何使用这条提示词
- 1复制上方完整提示词。
- 2在对应模型中替换主题、人物或风格变量。
- 3生成后记录有效调整,形成自己的版本。

