Launch a Sandbox¶
Uni-Agent provides an isolated and persistent execution environment for agents. Files, installed packages, and runtime state remain available across interactions within the same sandbox session.
This guide focuses on the ReAct Agent Tool workflow. It uses examples/quickstart/sandbox/demo.py to install a package, create and edit a Python script, execute it, and verify that state persists across tool calls.
About demo.py and DEBUG_MODE
You can use this demo.py to run an end-to-end sandbox check.
Set DEBUG_MODE=1 to display the per-session INFO walkthrough in the console.
Start a Sandbox¶
Choose a Sandbox Backend¶
Uni-Agent supports multiple sandbox backends. Choose the backend that matches your workflow. Providers are loaded lazily, so only the selected backend SDK needs to be installed.
Local, non-isolated. Commands run directly on the host.
Local execution can modify your machine
Commands can read, modify, or delete local files and change the active Python environment. Use this backend only for small-scale validation with trusted commands.
Local, isolated. Docker runs agents in containers on your machine.
Integration and configuration instructions are to be filled.
Remote cloud service. veFaaS provides elastic, isolated sandboxes on Volcengine.
Install its client dependencies:
Configure the veFaaS endpoint and Volcengine credentials. You can follow the Volcengine tutorial to obtain the required configuration parameters.
export VEFAAS_FUNCTION_ID="<function-id>"
export VEFAAS_FUNCTION_ROUTE="<function-route>"
export VOLCE_ACCESS_KEY="<access-key>"
export VOLCE_SECRET_KEY="<secret-key>"
Create the sandbox configuration:
Remote cloud service. Modal provides on-demand isolated sandboxes without requiring you to manage a cluster.
Install and authenticate the Modal client:
Alternatively, you can provide the Modal credentials through environment variables:
Configure the image, lifecycle timeout, and optional Modal app name:
Remote or self-hosted service. YuanRong provides elastic sandbox management for distributed agent workloads.
Integration and configuration instructions are to be filled.
Start and Stop the Sandbox¶
Build the selected provider from its configuration:
Entering the async context starts the selected backend. Exiting it releases remote resources:
Build a ReAct Toolbox¶
A ReAct agent interacts with the sandbox through tools. The demo binds a stateful shell and a file editor:
from uni_agent.tools import Toolbox
tool_specs = [
{"name": "stateful_shell", "command_timeout": 120},
{"name": "str_replace_editor"},
]
toolbox = Toolbox.from_specs(tool_specs, sandbox=sandbox)
Enter the toolbox and export the model-facing tool schemas:
stateful_shell is exposed to the model as shell. Tools route their operations through the sandbox backend.
Run Tool Calls¶
Use the shell tool to install dependencies and execute commands:
Use the editor to create a Python script inside the sandbox:
script = "import numpy as np\nprint(int(np.array([1, 2, 4]).sum()))\n"
await toolbox.call(
"str_replace_editor",
{
"command": "create",
"path": "/tmp/demo.py",
"file_text": script,
},
)
The shell can immediately run the file created by the editor:
Verify Persistence¶
All tools share the sandbox lifecycle and filesystem:
- Packages installed by one call remain available to later calls.
- Files written by the editor can be executed and read by the shell.
- The stateful shell preserves environment variables and its working directory.
- The editor is stateless; its files persist because they live in the shared sandbox.
For example, a later shell call still sees a previous cd:
await toolbox.call("shell", {"command": "cd /tmp"})
result = await toolbox.call("shell", {"command": "pwd; python3 demo.py"})
Both Sandbox and Toolbox use async context managers, so tools are closed and remote resources are released even if a call fails.
Run the Complete Demo¶
After configuring a supported backend above, run the complete connectivity and persistence check:
Next, you can run agent inference against a sandbox-backed task.