{"id":118591,"date":"2026-10-27T18:40:32","date_gmt":"2026-10-27T10:40:32","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/118591.html"},"modified":"2026-10-27T18:40:32","modified_gmt":"2026-10-27T10:40:32","slug":"%e3%80%90s03%e3%80%91%e5%bc%80%e6%ba%90%e9%a1%b9%e7%9b%aelearn-claude-code%e5%ad%a6%e4%b9%a0","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/118591.html","title":{"rendered":"\u3010S03\u3011\u5f00\u6e90\u9879\u76eelearn-claude-code\u5b66\u4e60"},"content":{"rendered":"<h2>s03: Permission \u2014 \u6267\u884c\u524d\u505a\u6743\u9650\u5224\u65ad<\/h2>\n<p>s02 \u7684 Agent \u6709 5 \u4e2a\u5de5\u5177\u3002file tools \u53d7 safe_path \u4fdd\u62a4&#xff0c;\u4f46 bash \u4e0d\u53d7\u9650\u5236\u3002\u8ba9\u5b83&#034;\u6e05\u7406\u4e00\u4e0b\u9879\u76ee&#034;&#xff0c;\u53ef\u80fd\u6267\u884c rm -rf \/\u3002<\/p>\n<p>\u5b89\u5168\u8fb9\u754c\u7531\u4ee3\u7801\u8d1f\u8d23&#xff0c;\u5224\u65ad\u53d1\u751f\u5728\u5de5\u5177\u6267\u884c\u4e4b\u524d\u3002<\/p>\n<hr \/>\n<h3>\u89e3\u51b3\u65b9\u6848<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261027104030-6ae07f9e42cd9.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>s02 \u7684\u5faa\u73af\u5b8c\u5168\u4fdd\u7559\u3002\u552f\u4e00\u7684\u53d8\u52a8\u662f\u5728\u5de5\u5177\u6267\u884c\u524d\u63d2\u5165 check_permission()\u3002\u6bcf\u4e2a\u5de5\u5177\u8c03\u7528\u4f9d\u6b21\u7ecf\u8fc7\u4e09\u9053\u95f8\u95e8&#xff1a;\u786c\u62d2\u7edd\u4f18\u5148&#xff0c;\u8f6f\u8be2\u95ee\u6b21\u4e4b&#xff0c;\u90fd\u6ca1\u547d\u4e2d\u5c31\u653e\u884c\u3002<\/p>\n<p>\u4e09\u9053\u95f8\u95e8\u5bf9\u5e94\u4e09\u79cd\u51b3\u7b56&#xff1a;<\/p>\n<table>\n<tr>\u95f8\u95e8\u4f5c\u7528\u547d\u4e2d\u540e<\/tr>\n<tbody>\n<tr>\n<td>1. \u62d2\u7edd\u5217\u8868<\/td>\n<td>\u6c38\u8fdc\u7981\u6b62\u7684\u64cd\u4f5c&#xff08;rm -rf \/\u3001sudo&#xff09;<\/td>\n<td>\u76f4\u63a5\u62d2\u7edd&#xff0c;\u4e0d\u6267\u884c<\/td>\n<\/tr>\n<tr>\n<td>2. \u89c4\u5219\u5339\u914d<\/td>\n<td>\u53d6\u51b3\u4e8e\u4e0a\u4e0b\u6587\u7684\u64cd\u4f5c&#xff08;\u8bfb\/\u5199\u5de5\u4f5c\u533a\u5916\u3001rm \u6587\u4ef6&#xff09;<\/td>\n<td>\u4ea4\u7ed9\u95f8\u95e8 3<\/td>\n<\/tr>\n<tr>\n<td>3. \u7528\u6237\u5ba1\u6279<\/td>\n<td>\u95f8\u95e8 2 \u547d\u4e2d\u540e&#xff0c;\u6682\u505c\u7b49\u7528\u6237\u786e\u8ba4<\/td>\n<td>\u7528\u6237\u51b3\u5b9a\u5141\u8bb8\u6216\u62d2\u7edd<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4e09\u9053\u90fd\u6ca1\u547d\u4e2d \u2192 \u76f4\u63a5\u6267\u884c\u3002\u5927\u90e8\u5206\u65e5\u5e38\u64cd\u4f5c\u8d70\u8fd9\u6761\u8def\u3002<\/p>\n<hr \/>\n<h3>\u5de5\u4f5c\u539f\u7406<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261027104031-6ae07f9f2f373.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u95f8\u95e8 1&#xff1a;\u4e00\u5f20\u786c\u62d2\u7edd\u8868&#xff0c;\u5148\u67e5&#xff0c;\u547d\u4e2d\u5c31\u8fd4\u56de\u963b\u6b62\u4fe1\u606f\u3002\u8fd9\u5f20\u8868\u4f7f\u7528\u7b80\u5355\u5b57\u7b26\u4e32\u5339\u914d\u6765\u8bf4\u660e\u6743\u9650\u95f8\u95e8\u7684\u4f4d\u7f6e&#xff0c;\u4e0d\u80fd\u89c6\u4e3a\u5b8c\u6574\u7684\u5b89\u5168\u8fb9\u754c\u3002<\/p>\n<p>DENY_LIST <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span><br \/>\n    <span class=\"token string\">&#034;rm -rf \/&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;sudo&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;shutdown&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;reboot&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token string\">&#034;mkfs&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;dd if&#061;&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;&gt; \/dev\/sda&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">]<\/span><\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">check_deny_list<\/span><span class=\"token punctuation\">(<\/span>command<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">str<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token operator\">&gt;<\/span> <span class=\"token builtin\">str<\/span> <span class=\"token operator\">|<\/span> <span class=\"token boolean\">None<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">for<\/span> pattern <span class=\"token keyword\">in<\/span> DENY_LIST<span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> pattern <span class=\"token keyword\">in<\/span> command<span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> <span class=\"token string-interpolation\"><span class=\"token string\">f&#034;Blocked: &#039;<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>pattern<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#039; is on the deny list&#034;<\/span><\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">None<\/span><\/p>\n<p>\u95f8\u95e8 2\u8d1f\u8d23\u89c4\u5219\u5339\u914d&#xff0c;\u7528\u6765\u63cf\u8ff0&#034;\u4ec0\u4e48\u65f6\u5019\u9700\u8981\u95ee\u7528\u6237&#034;\u3002\u6bcf\u6761\u89c4\u5219\u6307\u5b9a\u5de5\u5177\u548c\u68c0\u67e5\u6761\u4ef6\u3002<\/p>\n<p><span class=\"token keyword\">import<\/span> re<\/p>\n<p>DESTRUCTIVE_COMMAND_WORD <span class=\"token operator\">&#061;<\/span> re<span class=\"token punctuation\">.<\/span><span class=\"token builtin\">compile<\/span><span class=\"token punctuation\">(<\/span><br \/>\n    <span class=\"token string\">r&#034;(?i)(?:^|[;&amp;|()\\\\n])\\\\s*(?:rm|del)(?&#061;\\\\s|$|[;&amp;|()])&#034;<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">contains_destructive_command<\/span><span class=\"token punctuation\">(<\/span>command<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">str<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token operator\">&gt;<\/span> <span class=\"token builtin\">bool<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token builtin\">bool<\/span><span class=\"token punctuation\">(<\/span>DESTRUCTIVE_COMMAND_WORD<span class=\"token punctuation\">.<\/span>search<span class=\"token punctuation\">(<\/span>command<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>PERMISSION_RULES <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token string\">&#034;tools&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;read_file&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;write_file&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;edit_file&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        <span class=\"token string\">&#034;check&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token keyword\">lambda<\/span> args<span class=\"token punctuation\">:<\/span> <span class=\"token keyword\">not<\/span> <span class=\"token punctuation\">(<\/span>WORKDIR <span class=\"token operator\">\/<\/span> args<span class=\"token punctuation\">.<\/span>get<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;path&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span>resolve<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span>is_relative_to<span class=\"token punctuation\">(<\/span>WORKDIR<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        <span class=\"token string\">&#034;message&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;Access outside workspace&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token string\">&#034;tools&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;bash&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        <span class=\"token string\">&#034;check&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token keyword\">lambda<\/span> args<span class=\"token punctuation\">:<\/span> contains_destructive_command<span class=\"token punctuation\">(<\/span>args<span class=\"token punctuation\">.<\/span>get<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;command&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">or<\/span> <span class=\"token builtin\">any<\/span><span class=\"token punctuation\">(<\/span><br \/>\n            kw <span class=\"token keyword\">in<\/span> args<span class=\"token punctuation\">.<\/span>get<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;command&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;&#034;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">for<\/span> kw <span class=\"token keyword\">in<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;rm &#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;&gt; \/etc\/&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;chmod 777&#034;<\/span><span class=\"token punctuation\">]<\/span><br \/>\n        <span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        <span class=\"token string\">&#034;message&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;Potentially destructive command&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">]<\/span><\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">check_rules<\/span><span class=\"token punctuation\">(<\/span>tool_name<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">str<\/span><span class=\"token punctuation\">,<\/span> args<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">dict<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token operator\">&gt;<\/span> <span class=\"token builtin\">str<\/span> <span class=\"token operator\">|<\/span> <span class=\"token boolean\">None<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">for<\/span> rule <span class=\"token keyword\">in<\/span> PERMISSION_RULES<span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> tool_name <span class=\"token keyword\">in<\/span> rule<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;tools&#034;<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token keyword\">and<\/span> rule<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;check&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">(<\/span>args<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> rule<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;message&#034;<\/span><span class=\"token punctuation\">]<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">None<\/span><\/p>\n<p>\u95f8\u95e8 3&#xff1a;\u89c4\u5219\u547d\u4e2d\u540e&#xff0c;\u6682\u505c\u7b49\u7528\u6237\u8f93\u5165\u3002<\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">ask_user<\/span><span class=\"token punctuation\">(<\/span>tool_name<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">str<\/span><span class=\"token punctuation\">,<\/span> args<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">dict<\/span><span class=\"token punctuation\">,<\/span> reason<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">str<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token operator\">&gt;<\/span> <span class=\"token builtin\">str<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f&#034;\\\\n\u26a0  <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>reason<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f&#034;   Tool: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>tool_name<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">(<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>args<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">)&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n    choice <span class=\"token operator\">&#061;<\/span> <span class=\"token builtin\">input<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;   Allow? [y\/N] &#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span>strip<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span>lower<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;allow&#034;<\/span> <span class=\"token keyword\">if<\/span> choice <span class=\"token keyword\">in<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;y&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;yes&#034;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">else<\/span> <span class=\"token string\">&#034;deny&#034;<\/span><\/p>\n<p>\u4e09\u9053\u95f8\u95e8\u4e32\u5728\u4e00\u8d77&#xff0c;\u63d2\u5728\u5de5\u5177\u6267\u884c\u4e4b\u524d&#xff1a;<\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">check_permission<\/span><span class=\"token punctuation\">(<\/span>block<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token operator\">&gt;<\/span> <span class=\"token builtin\">bool<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token comment\"># \u95f8\u95e8 1: \u786c\u62d2\u7edd<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> block<span class=\"token punctuation\">.<\/span>name <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token string\">&#034;bash&#034;<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        reason <span class=\"token operator\">&#061;<\/span> check_deny_list<span class=\"token punctuation\">(<\/span>block<span class=\"token punctuation\">.<\/span><span class=\"token builtin\">input<\/span><span class=\"token punctuation\">.<\/span>get<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;command&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> reason<span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f&#034;\\\\n\u26d4 <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>reason<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">False<\/span><\/p>\n<p>    <span class=\"token comment\"># \u95f8\u95e8 2 &#043; 3: \u89c4\u5219\u5339\u914d \u2192 \u7528\u6237\u5ba1\u6279<\/span><br \/>\n    reason <span class=\"token operator\">&#061;<\/span> check_rules<span class=\"token punctuation\">(<\/span>block<span class=\"token punctuation\">.<\/span>name<span class=\"token punctuation\">,<\/span> block<span class=\"token punctuation\">.<\/span><span class=\"token builtin\">input<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> reason<span class=\"token punctuation\">:<\/span><br \/>\n        decision <span class=\"token operator\">&#061;<\/span> ask_user<span class=\"token punctuation\">(<\/span>block<span class=\"token punctuation\">.<\/span>name<span class=\"token punctuation\">,<\/span> block<span class=\"token punctuation\">.<\/span><span class=\"token builtin\">input<\/span><span class=\"token punctuation\">,<\/span> reason<span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> decision <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token string\">&#034;deny&#034;<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">False<\/span><\/p>\n<p>    <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">True<\/span><\/p>\n<p><span class=\"token comment\"># \u5728 agent_loop \u4e2d\u2014\u2014s02 \u7684\u5faa\u73af\u53ea\u52a0\u4e86\u4e00\u884c&#xff1a;<\/span><br \/>\n<span class=\"token keyword\">for<\/span> block <span class=\"token keyword\">in<\/span> tool_calls<span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token keyword\">not<\/span> check_permission<span class=\"token punctuation\">(<\/span>block<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span>           <span class=\"token comment\"># \u2190 \u65b0\u589e<\/span><br \/>\n        results<span class=\"token punctuation\">.<\/span>append<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">{<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span> <span class=\"token string\">&#034;content&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;Permission denied.&#034;<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">continue<\/span><br \/>\n    output <span class=\"token operator\">&#061;<\/span> TOOL_HANDLERS<span class=\"token punctuation\">[<\/span>block<span class=\"token punctuation\">.<\/span>name<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">**<\/span>block<span class=\"token punctuation\">.<\/span><span class=\"token builtin\">input<\/span><span class=\"token punctuation\">)<\/span>  <span class=\"token comment\"># s02 \u539f\u6709<\/span><br \/>\n    results<span class=\"token punctuation\">.<\/span>append<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<hr \/>\n<h3>\u76f8\u5bf9 s02 \u7684\u53d8\u66f4<\/h3>\n<table>\n<tr>\u7ec4\u4ef6\u4e4b\u524d (s02)\u4e4b\u540e (s03)<\/tr>\n<tbody>\n<tr>\n<td>\u5b89\u5168\u6a21\u578b<\/td>\n<td>\u65e0&#xff08;\u4fe1\u4efb\u6a21\u578b&#xff09;<\/td>\n<td>\u4e09\u9053\u95f8\u95e8\u6743\u9650\u7ba1\u7ebf<\/td>\n<\/tr>\n<tr>\n<td>\u65b0\u51fd\u6570<\/td>\n<td>\u2014<\/td>\n<td>check_deny_list, check_rules, ask_user, check_permission<\/td>\n<\/tr>\n<tr>\n<td>\u5faa\u73af<\/td>\n<td>\u76f4\u63a5\u6267\u884c\u6240\u6709\u5de5\u5177<\/td>\n<td>\u6267\u884c\u524d\u63d2\u5165 check_permission()<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u8bd5\u4e00\u4e0b<\/h3>\n<p><span class=\"token builtin class-name\">cd<\/span> learn-claude-code<br \/>\npython s03_permission\/code.py<\/p>\n<p>\u8bd5\u8bd5\u8fd9\u4e9b prompt&#xff1a;<\/p>\n<li>Create a file called test.txt in the current directory&#xff08;\u5e94\u8be5\u76f4\u63a5\u901a\u8fc7&#xff09;<\/li>\n<li>Delete the file test.txt&#xff08;bash &#043; rm \u4f1a\u89e6\u53d1\u95f8\u95e8 2&#xff09;<\/li>\n<li>What files are in the current directory?&#xff08;\u53ea\u8bfb&#xff0c;\u5168\u90e8\u901a\u8fc7&#xff09;<\/li>\n<li>Try to write a file to \/etc\/something&#xff08;\u5199\u5de5\u4f5c\u533a\u5916&#xff0c;\u89e6\u53d1\u95f8\u95e8 2&#xff09;<\/li>\n<li>\u5728 Windows \u4e0a&#xff0c;del test.txt \u548c DEL test.txt \u4f1a\u89e6\u53d1\u95f8\u95e8 2&#xff0c;\u800c model\u3001delimiter \u548c echo del test.txt \u4e0d\u4f1a\u3002<\/li>\n<p>\u89c2\u5bdf\u91cd\u70b9&#xff1a;\u54ea\u4e9b\u64cd\u4f5c\u76f4\u63a5\u901a\u8fc7&#xff1f;\u54ea\u4e9b\u9700\u8981\u4f60\u786e\u8ba4&#xff1f;\u54ea\u4e9b\u88ab\u76f4\u63a5\u62d2\u7edd&#xff1f;<\/p>\n<hr \/>\n<p>\u6e90\u7801\u5730\u5740&#xff1a;https:\/\/github.com\/shareAI-lab\/learn-claude-code<br \/>\n\u84dd\u594f\u4e91\u5730\u5740&#xff1a;https:\/\/wwbfs.lanzouv.com\/iva494dg0h4f<br \/>\n\u5bc6\u7801:cc39<\/p>\n<p>\u8f9b\u8f9b\u82e6\u82e6\u5199\u5b8c&#xff0c;\u4e0d\u77e5\u9053csdn\u62bd\u4ec0\u4e48\u98ce&#xff0c;\u4fdd\u5b58\u8349\u7a3f\u6ca1\u6210\u529f&#xff0c;\u5c31\u8fd9\u5f20\u5c31\u91cd\u65b0\u53d1\u539f\u6587\u4e86<\/p>\n","protected":false},"excerpt":{"rendered":"<p>s03: Permission \u2014 \u6267\u884c\u524d\u505a\u6743\u9650\u5224\u65ad<br \/>\ns02 \u7684 Agent \u6709 5 \u4e2a\u5de5\u5177\u3002file tools \u53d7 safe_path \u4fdd\u62a4&#xff0c;\u4f46 bash \u4e0d\u53d7\u9650\u5236\u3002\u8ba9\u5b83\\&#8221;\u6e05\u7406\u4e00\u4e0b\u9879\u76ee\\&#8221;&#xff0c;\u53ef\u80fd\u6267\u884c rm -rf \/\u3002<br \/>\n\u5b89\u5168\u8fb9\u754c\u7531\u4ee3\u7801\u8d1f\u8d23&#xff0c;\u5224\u65ad\u53d1\u751f\u5728\u5de5\u5177\u6267\u884c\u4e4b\u524d\u3002\u89e3\u51b3\u65b9\u6848s02 \u7684\u5faa\u73af\u5b8c\u5168\u4fdd\u7559\u3002\u552f\u4e00\u7684\u53d8\u52a8\u662f\u5728\u5de5\u5177\u6267\u884c\u524d\u63d2\u5165 check_permission()\u3002\u6bcf\u4e2a\u5de5\u5177\u8c03\u7528\u4f9d\u6b21\u7ecf\u8fc7\u4e09\u9053\u95f8\u95e8&#xff1a;\u786c\u62d2\u7edd\u4f18\u5148&#xff0c;\u8f6f<\/p>\n","protected":false},"author":2,"featured_media":118589,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[81,50,305],"topic":[],"class_list":["post-118591","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-python","tag-50","tag-305"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010S03\u3011\u5f00\u6e90\u9879\u76eelearn-claude-code\u5b66\u4e60 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/118591.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010S03\u3011\u5f00\u6e90\u9879\u76eelearn-claude-code\u5b66\u4e60 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"s03: Permission \u2014 \u6267\u884c\u524d\u505a\u6743\u9650\u5224\u65ad s02 \u7684 Agent \u6709 5 \u4e2a\u5de5\u5177\u3002file tools \u53d7 safe_path \u4fdd\u62a4&#xff0c;\u4f46 bash \u4e0d\u53d7\u9650\u5236\u3002\u8ba9\u5b83&quot;\u6e05\u7406\u4e00\u4e0b\u9879\u76ee&quot;&#xff0c;\u53ef\u80fd\u6267\u884c rm -rf \/\u3002 \u5b89\u5168\u8fb9\u754c\u7531\u4ee3\u7801\u8d1f\u8d23&#xff0c;\u5224\u65ad\u53d1\u751f\u5728\u5de5\u5177\u6267\u884c\u4e4b\u524d\u3002\u89e3\u51b3\u65b9\u6848s02 \u7684\u5faa\u73af\u5b8c\u5168\u4fdd\u7559\u3002\u552f\u4e00\u7684\u53d8\u52a8\u662f\u5728\u5de5\u5177\u6267\u884c\u524d\u63d2\u5165 check_permission()\u3002\u6bcf\u4e2a\u5de5\u5177\u8c03\u7528\u4f9d\u6b21\u7ecf\u8fc7\u4e09\u9053\u95f8\u95e8&#xff1a;\u786c\u62d2\u7edd\u4f18\u5148&#xff0c;\u8f6f\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/118591.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-27T10:40:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261027104030-6ae07f9e42cd9.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/118591.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/118591.html\",\"name\":\"\u3010S03\u3011\u5f00\u6e90\u9879\u76eelearn-claude-code\u5b66\u4e60 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-27T10:40:32+00:00\",\"dateModified\":\"2026-10-27T10:40:32+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/118591.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/118591.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/118591.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010S03\u3011\u5f00\u6e90\u9879\u76eelearn-claude-code\u5b66\u4e60\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u3010S03\u3011\u5f00\u6e90\u9879\u76eelearn-claude-code\u5b66\u4e60 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/118591.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010S03\u3011\u5f00\u6e90\u9879\u76eelearn-claude-code\u5b66\u4e60 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"s03: Permission \u2014 \u6267\u884c\u524d\u505a\u6743\u9650\u5224\u65ad s02 \u7684 Agent \u6709 5 \u4e2a\u5de5\u5177\u3002file tools \u53d7 safe_path \u4fdd\u62a4&#xff0c;\u4f46 bash \u4e0d\u53d7\u9650\u5236\u3002\u8ba9\u5b83\"\u6e05\u7406\u4e00\u4e0b\u9879\u76ee\"&#xff0c;\u53ef\u80fd\u6267\u884c rm -rf \/\u3002 \u5b89\u5168\u8fb9\u754c\u7531\u4ee3\u7801\u8d1f\u8d23&#xff0c;\u5224\u65ad\u53d1\u751f\u5728\u5de5\u5177\u6267\u884c\u4e4b\u524d\u3002\u89e3\u51b3\u65b9\u6848s02 \u7684\u5faa\u73af\u5b8c\u5168\u4fdd\u7559\u3002\u552f\u4e00\u7684\u53d8\u52a8\u662f\u5728\u5de5\u5177\u6267\u884c\u524d\u63d2\u5165 check_permission()\u3002\u6bcf\u4e2a\u5de5\u5177\u8c03\u7528\u4f9d\u6b21\u7ecf\u8fc7\u4e09\u9053\u95f8\u95e8&#xff1a;\u786c\u62d2\u7edd\u4f18\u5148&#xff0c;\u8f6f","og_url":"https:\/\/www.wsisp.com\/helps\/118591.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-27T10:40:32+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261027104030-6ae07f9e42cd9.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/118591.html","url":"https:\/\/www.wsisp.com\/helps\/118591.html","name":"\u3010S03\u3011\u5f00\u6e90\u9879\u76eelearn-claude-code\u5b66\u4e60 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-27T10:40:32+00:00","dateModified":"2026-10-27T10:40:32+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/118591.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/118591.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/118591.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010S03\u3011\u5f00\u6e90\u9879\u76eelearn-claude-code\u5b66\u4e60"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/118591","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=118591"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/118591\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/118589"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=118591"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=118591"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=118591"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=118591"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}