41 lines
1.3 KiB
Markdown
41 lines
1.3 KiB
Markdown
---
|
|
title: "Lambda Safety Gate"
|
|
type: concept
|
|
tags: []
|
|
last_updated: 2026-05-01
|
|
---
|
|
|
|
## Definition
|
|
|
|
在执行 SLM 生成的 Python lambda 转换函数前,对其进行严格安全验证的防御机制。防止恶意代码、文件系统操作或任意代码执行通过 AI 修复管道注入系统。
|
|
|
|
## Validation Rules
|
|
|
|
```python
|
|
def validate_lambda(lambda_str: str) -> bool:
|
|
forbidden = ['import', 'exec', 'eval', 'os.', 'subprocess', '__']
|
|
if not lambda_str.startswith('lambda'):
|
|
raise ValueError("Rejected: output must be a lambda function")
|
|
if any(term in lambda_str for term in forbidden):
|
|
raise ValueError("Rejected: forbidden term in lambda")
|
|
return True
|
|
```
|
|
|
|
## Validation Checklist
|
|
|
|
| Check | Rule | On Failure |
|
|
|-------|------|------------|
|
|
| Prefix | 必须以 `lambda` 开头 | 拒绝,路由至人工隔离 |
|
|
| Keywords | 禁止 `import/exec/eval/os/subprocess/__` | 拒绝,路由至人工隔离 |
|
|
| Confidence | 置信度必须 ≥ 0.75 | 拒绝,路由至人工隔离 |
|
|
|
|
## Rationale
|
|
|
|
AI 生成的文本可能包含任意代码。Lambda Safety Gate 确保即使 SLM 被注入恶意提示词,修复管道也仅执行无害的数据转换函数。
|
|
|
|
## Related
|
|
|
|
- [[Air-Gapped SLM Fix Generation]]
|
|
- [[Zero Data Loss Guarantee]]
|
|
- [[AI Generates Logic Not Data]]
|