This topic describes how to build a full-featured All-in-One Sandbox environment using the AgentBay Linux Computer Use image.
Background
The All-in-One Sandbox is a highly integrated cloud development and execution environment. It combines Linux desktop automation, a browser, and a code execution engine. This provides a standardized, out-of-the-box runtime environment for automated tasks (especially AI agents), cloud development, and secure code execution.
This solution uses a unified containerization architecture to eliminate environmental differences, file transfer complexities, and interaction barriers found in legacy, fragmented toolchains. This approach enables end-to-end integration and seamless operations.
Solution overview
This solution uses a Linux sandbox session as an all-in-one sandbox. It uses the linux_latest image to perform the following:
session.computerfor desktop automation.session.browserfor browser automation.session.codefor code execution (such as Python).
This environment is particularly useful when you need to perform user interface interactions and script execution (or quickly retrieve web content) in a single session without switching images.
Core features
Environment consistency: Encapsulates the browser, terminal, file system, and developer tools in a unified environment to eliminate inconsistencies.
Out-of-the-box: Comes pre-installed with common languages, frameworks, and build tools to save time on environment setup.
Security isolation: Uses the VPC and an independent container environment to ensure secure task execution and data control.
Auto scaling: Supports creating and destroying environments in seconds with on-demand resource configuration for cost optimization.
Multimodal integration: Integrates Browser Use, Code Space, and Computer Use capabilities within a single Linux image for seamless toolchain collaboration.
Preparations
Complete the API key settings in your environment.
Implementation examples
The following examples use the same linux_latest session type and demonstrate:
Running code with
session.code.run_code().Using the browser agent API with
session.browser.
Example 1: Run code in linux_latest (similar to Code space)
import os
from agentbay import AgentBay, CreateSessionParams
def main() -> None:
api_key = os.getenv("AGENTBAY_API_KEY")
if not api_key:
raise RuntimeError("AGENTBAY_API_KEY environment variable not set")
ab = AgentBay(api_key=api_key)
create_result = ab.create(CreateSessionParams(image_id="linux_latest"))
if not create_result.success:
raise RuntimeError(create_result.error_message)
session = create_result.session
try:
code = """
print("RUN_CODE_OK")
print(6 * 7)
""".strip()
result = session.code.run_code(code, "python")
if not result.success:
raise RuntimeError(result.error_message)
print(result.result)
finally:
session.delete()
if __name__ == "__main__":
main()
Example 2: Use the browser API in linux_latest
This example uses the browser agent API (no local Playwright required) to navigate to a page and take a screenshot.
import os
from agentbay import AgentBay, BrowserOption, CreateSessionParams
def main() -> None:
api_key = os.getenv("AGENTBAY_API_KEY")
if not api_key:
raise RuntimeError("AGENTBAY_API_KEY environment variable not set")
ab = AgentBay(api_key=api_key)
create_result = ab.create(CreateSessionParams(image_id="linux_latest"))
if not create_result.success:
raise RuntimeError(create_result.error_message)
session = create_result.session
try:
if not session.browser.initialize(BrowserOption()):
raise RuntimeError("Failed to initialize browser")
session.browser.agent.navigate("https://example.com")
data = session.browser.agent.screenshot(full_page=False)
print("Screenshot data prefix:", data[:30])
finally:
session.delete()
if __name__ == "__main__":
main()