Using BoxRun? If your agent communicates via HTTP, BoxRun’s REST API or Python SDK may be a simpler integration path. BoxRun handles sandbox lifecycle, file upload/download, and SSE streaming out of the box. See the AI agent patterns section in the BoxRun SDK docs.
Recommended Configuration
Workload-Type Reference
Starter Configuration
- Python
- Node.js
Security Presets
SecurityOptions has three presets:
For AI agents running untrusted code, use
SecurityOptions.maximum():
- Python
- Node.js
Concurrency Model
One Box, Multiple Executions (Recommended)
A single box can run manyexec() calls. Each call spawns a new process inside the same VM. This avoids repeated VM boot overhead and is safe because the VM provides hardware isolation from the host.
- Python
- Node.js
One Box Per Agent
Use separate boxes when you need strict isolation between agents, different images, or independent resource limits.- Python
- Node.js
Timeout Handling and Zombie Prevention
The Problem
asyncio.wait_for() cancels the Python coroutine but does not kill the guest process. Without explicit cleanup, the process continues running inside the VM indefinitely.
Correct Pattern
Always kill the execution in the timeout handler:- Python
- Node.js
Defensive Helper
For maximum safety, combine timeout handling with a try/finally block:- Python
- Node.js
Security Boundaries
SecurityOptions Fields
Network Isolation
To prevent an agent from accessing the network:- Python
- Node.js
In the Python bindings,
network_enabled is currently a macOS-only control. On Linux and other platforms, network isolation is typically enforced by the container/runtime networking configuration (for example, running in an isolated network namespace and not publishing ports), and network_enabled may not itself hard-disable all outbound connectivity.Resource Limits as Security Boundaries
Resource limits prevent a rogue agent from consuming all host resources:Memory Limits and OOM
Thememory_mib setting is a hard limit enforced by the hypervisor. When a guest process exceeds this limit, the Linux OOM killer terminates the offending process inside the VM — but the box itself stays running. This means you can detect OOM and retry or report the failure.
How to detect OOM:
- The process exit code will be 137 (128 + SIGKILL)
stderrmay containKilledorOut of memory
Terminal Resizing
When running interactive TTY sessions (e.g., an AI agent controlling a shell), useresize_tty() to set the terminal dimensions. This ensures proper line wrapping and avoids garbled output from programs that query terminal size.
- Python
- Node.js
resize_tty() / resizeTty() only works on executions started with tty=True / { tty: true }. Calling it on a non-TTY execution returns an error.Complete Example
Putting it all together: security configuration, concurrent execution with timeouts, and cleanup.- Python
- Node.js
See also
- Tutorials — Step-by-step walkthroughs for code execution, file transfer, LLM integration, and browser automation
- BoxRun Python SDK — AI agent patterns — Agent integration via REST API
- BoxRun REST API — HTTP endpoints for sandbox management
- SDK Reference — Full API reference for all BoxLite SDKs
- Architecture — How BoxLite isolation works

