FoundationAgents/OpenManus · error · RuntimeError
Sandbox not initialized
Error message
Sandbox not initialized
What it means
Raised by DockerSandbox.run_command (app/sandbox/core/sandbox.py:155) when self.terminal is None — i.e. the command API was used before a successful create()/init(). The sandbox object can be constructed cheaply, but the exec terminal only exists after DockerSandbox.create() completes; calling run_command before that is a lifecycle misuse, not a Docker failure.
Source
Thrown at app/sandbox/core/sandbox.py:155
os.makedirs(host_path, exist_ok=True)
return host_path
async def run_command(self, cmd: str, timeout: Optional[int] = None) -> str:
"""Runs a command in the sandbox.
Args:
cmd: Command to execute.
timeout: Timeout in seconds.
Returns:
Command output as string.
Raises:
RuntimeError: If sandbox not initialized or command execution fails.
TimeoutError: If command execution times out.
"""
if not self.terminal:
raise RuntimeError("Sandbox not initialized")
try:
return await self.terminal.run_command(
cmd, timeout=timeout or self.config.timeout
)
except TimeoutError:
raise SandboxTimeoutError(
f"Command execution timed out after {timeout or self.config.timeout} seconds"
)
async def read_file(self, path: str) -> str:
"""Reads a file from the container.
Args:
path: File path.
Returns:
File contents as string.View on GitHub (pinned to 52a13f2a57)
Solutions
- Call `sandbox = await DockerSandbox(config).create()` (or manager.create_sandbox + get_sandbox) before any run_command.
- After any create/cleanup failure, drop the reference — do not retry commands on the same object.
- If using the manager, always go through get_sandbox(sandbox_id) which only returns initialized sandboxes.
Example fix
# before
sb = DockerSandbox(config)
out = await sb.run_command("ls") # RuntimeError: Sandbox not initialized
# after
sb = await DockerSandbox(config).create()
out = await sb.run_command("ls") Defensive patterns
Strategy: type-guard
Validate before calling
assert sandbox.terminal is not None, "call await sandbox.create() before run_command"
Type guard
def is_ready(sb: DockerSandbox) -> bool:
return sb.terminal is not None Try / catch
try:
out = await sandbox.run_command(cmd)
except RuntimeError as e:
if str(e) == "Sandbox not initialized":
sandbox = await DockerSandbox(sandbox.config).create()
out = await sandbox.run_command(cmd)
else:
raise Prevention
- Always obtain sandboxes via SandboxManager.get_sandbox(sid)
- Await create() fully before any command
- Drop references after cleanup() or a failed create()
- Wrap sandbox usage in a context helper that guarantees init order
When it happens
Trigger: Constructing DockerSandbox(config) directly and calling run_command without `await sandbox.create()`; using a sandbox after cleanup() set terminal to None; a create() that failed (error 24) leaving the object alive and later reused.
Common situations: Skipping the manager and hand-rolling the sandbox lifecycle; forgetting to await the create coroutine (calling create() without await so it never runs); reusing a sandbox reference after an exception path already cleaned it up.
Related errors
- Failed to create sandbox: {e}
- password must be provided
- Maximum number of sandboxes ({self.max_sandboxes}) reached
- Failed to create sandbox: {e}
- Command execution timed out after {timeout or self.config.ti
AI-assisted analysis of FoundationAgents/OpenManus@52a13f2a57 (2026-08-15).
Data as JSON: /api/errors/e316312e653fa20d.
Report an issue: GitHub.