Ephemeral AST Code Sandboxes for AI Agents: Zero Cold-Start Execution Without Cloud VM Latency
说明与用途
AI 代理的本地沙箱通过 AST 分析、虚拟文件系统和基于令牌的输出限制,实现无云延迟和成本的安全 Python 执行。
问题
AI coding agents need isolated execution of Python code, but cloud microVMs introduce cold‑start latency, costs, and context window blowout.
结果
Local sandbox achieves sub‑millisecond overhead, blocks dangerous imports in <0.2 ms, limits output to 1,000 tokens, and tracks file changes via VFS.
工作流
- Install via pip: pip install agent-code-sandbox
- Create CodeSandbox with SandboxConfig (timeout, max_output_tokens, allow_network)
- Execute safe Python code with sandbox.execute_python
- Malicious code is rejected by AST guard before execution
- Run MCP server to expose execute_python, execute_command, inspect_code_security tools
证据
Cold-Start Latency: 1.5s to 4s to provision a microVM per execution.
Sub‑millisecond time (<0.2ms overhead)
Security Verdict: FORBIDDEN_IMPORT_DETECTED: os
- 记录日期: 2026-11-04T00:14:16.807Z