Skip to content

ADB shell

You can use the adb_shell feature of the Sandbox to:

  • Run shell commands inside the Android environment
  • Transfer files between the host and the Android sandbox
  • Manage apps and system resources within the sandbox

Tip: Always call sbx.adb_shell.connect() before running commands, and sbx.adb_shell.close() when done.

The connect() method must be called before any other adb_shell methods.

from agentbox import Sandbox

# Create sandbox
sbx = Sandbox(
    api_key="ab_xxxxxxxxxxxxxxxxxxxxxxxxx",
    template="wemmodr8mb2uk3kn7exw",
    timeout=60
)

try:
    # Connect adb shell
    sbx.adb_shell.connect()

    # Run shell command
    result = sbx.adb_shell.shell("ls /")
    print("Output:", result)

    ...
finally:
    sbx.adb_shell.close()
# Upload file to sandbox
sbx.adb_shell.push("./pytest.ini", "/data/local/tmp/pytest.ini")

# Download file from sandbox
sbx.adb_shell.pull("/data/local/tmp/pytest.ini", "./pytest002.ini")

# Read file content inside sandbox
ret = sbx.files.read("/data/local/tmp/pytest.ini")
print("get ret:", ret)

# Check file existence
isExist = sbx.adb_shell.exists("/data/local/tmp/pytest.ini")
print("isExist:", isExist)

# Remove file
sbx.adb_shell.shell("rm -f /data/local/tmp/pytest.ini")
isExist = sbx.adb_shell.exists("/data/local/tmp/pytest.ini")
print("isExist:", isExist)
# List installed packages
pmList = sbx.adb_shell.shell("pm list packages")
if "baidu" in pmList.lower():
    print("Found a package with 'baidu' in its name")
else:
    print("No package with 'baidu' found")
# Install APK
sbx.adb_shell.install("./baidusearch_AndroidPhone_757p.apk", True)

# Verify installation
pmList = sbx.adb_shell.shell("pm list packages")
if "baidu" in pmList.lower():
    print("1 Found a package with 'baidu' in its name")
else:
    print("1 No package with 'baidu' found")
# Uninstall APK
sbx.adb_shell.uninstall("com.baidu.searchbox")

# Verify uninstallation
pmList = sbx.adb_shell.shell("pm list packages")
if "baidu" in pmList.lower():
    print("2 Found a package with 'baidu' in its name")
else:
    print("2 No package with 'baidu' found")