Dev.to|📄 原文链接|2026-07-22 收录

smolagents 沙箱破坏了 Python 最基础的解包语句——a, *b = list 不再工作

来源:dev.to/himanshu_748 — 2026-07-21 发布

📋 概述

smolagents 的 AST 解释器沙箱在处理赋值目标时只处理了一种形状:固定大小的 ast.Tuple。这导致三个基础 Python 语法全部被破坏:星号解包(a, *b = list)报错"无法解包错误大小的元组"——尽管大小完全正确;a, b = "hi" 拒绝解包字符串(Python 原生支持);列表模式 [a, b] = [1, 2] 静默不赋值——不报错但也不赋值,最危险的静默失败。根因是 set_value 函数有三个坑:星号标记从未被检查、字符串被显式排除出可迭代路径、ast.List 不匹配任何分支。更糟的是错误消息本身就是谎言,导致 LLM 代理反复重试相同的有效代码。

🔑 核心要点

💡 金句

The error is handled: the agent catches it and feeds it back to the model as guidance. But the guidance is wrong, so the model cannot act on it, so it loops.
← 返回 Dev.to 首页