All in One Sandbox

Updated at:

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, enabling end-to-end integration and seamless operations.

Solution overview

This solution uses a single linux_latest session as an all-in-one sandbox that exposes three capabilities through one unified API:

  • session.computer — control the Linux desktop.

  • session.browser — automate a managed browser without installing Playwright locally.

  • session.code — run scripts in Python (and other supported languages).

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.

Which capability to use

Task

Use

Interact with a web page (navigate, click, scrape)

session.browser

Operate a GUI application or capture the full desktop

session.computer

Run a script or execute arbitrary code

session.code

Use all three in the same session when your workflow spans more than one of these tasks.

Key capabilities

  • Consistent environment: The browser, terminal, file system, and developer tools run inside one container, so there are no environment mismatches between steps.

  • Ready to run: Common languages, frameworks, and build tools are pre-installed. No environment setup required.

  • Security isolation: Each session runs in a dedicated container inside a Virtual Private Cloud (VPC), keeping task execution and data contained.

  • On-demand scaling: Sessions start and stop in seconds with on-demand resource configuration for cost optimization.

  • Unified toolchain: Browser Use, Code Space, and Computer Use capabilities are available in one image — no image switching mid-workflow.

Prerequisites

Before you begin, ensure that you have:

Run code and automate a browser

Both examples use the same linux_latest session type and cover the two most common tasks:

  • Running code with session.code.run_code().

  • Navigating and screenshotting a page with session.browser.

Run Python code in linux_latest

This example runs a Python snippet inside the sandbox — equivalent to a cloud code space, but within an agent session that can also drive a browser or the desktop.

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()
    

Automate a browser session in linux_latest

This example uses the browser agent API — no local Playwright required — to open a URL and capture 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()
    

References