AI sandbox: isolation, code execution, and costs
说明与用途
关于为 AI 代码执行选择和使用隔离环境的指南,包括 Firecracker 运行时检查、资源限制和安全密钥处理。
问题
Choosing a runtime for an AI agent that can run code while ensuring isolation, resource limits, and cost control.
结果
The example demonstrates a secure, cost‑aware execution of a Python task in a Firecracker sandbox, with runtime checks and output validation.
工作流
- Receive task from backend
- Ask model to produce code
- Create sandbox with specified size and timeout
- Verify sandbox runtime is Firecracker
- Write Python script to /tmp/task.py
- Execute script inside sandbox
- Collect stdout, stderr, exit code
- Validate and sanitize output
- Stop and clean up sandbox
证据
An AI sandbox is an isolated environment where an AI agent can run code, install packages, and work with files.
Lizard Sandboxes use Firecracker. Older volumes or snapshots, and a fallback after a failed Firecracker start, can use the container runtime.
Keep the model provider key and the sandbox management key in your backend. Giving generated code a management key would let it request more resources using your account.
- 记录日期: 2026-10-16T21:41:15.322Z