ADB shell
ADB shell usage
Section titled “ADB shell usage”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.
Connect & run basic shell command
Section titled “Connect & run basic shell command”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()
from agentbox import AsyncSandbox
# Create sandbox
sbx = await AsyncSandbox.create(
api_key="ab_xxxxxxxxxxxxxxxxxxxxxxxxx",
template="wemmodr8mb2uk3kn7exw",
timeout=60
)
try:
# Connect adb shell
await sbx.adb_shell.connect()
# Run shell command
result = await sbx.adb_shell.shell("ls /")
print("Output:", result)
...
finally:
await sbx.adb_shell.close()
Upload, download, and read files
Section titled “Upload, download, and read files”# 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)
# Upload file to sandbox
await sbx.adb_shell.push("./pytest.ini", "/data/local/tmp/pytest.ini")
# Download file from sandbox
await sbx.adb_shell.pull("/data/local/tmp/pytest.ini", "./pytest002.ini")
# Read file content inside sandbox
ret = await sbx.files.read("/data/local/tmp/pytest.ini")
print("get ret:", ret)
# Check file existence
isExist = await sbx.adb_shell.exists("/data/local/tmp/pytest.ini")
print("isExist:", isExist)
# Remove file
await sbx.adb_shell.shell("rm -f /data/local/tmp/pytest.ini")
isExist = await sbx.adb_shell.exists("/data/local/tmp/pytest.ini")
print("isExist:", isExist)
List installed packages
Section titled “List installed packages”# 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")
# List installed packages
pmList = await 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 and verify
Section titled “Install APK and verify”# 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")
# Install APK
await sbx.adb_shell.install("./baidusearch_AndroidPhone_757p.apk", True)
# Verify installation
pmList = await 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 and verify
Section titled “Uninstall APK and verify”# 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")
# Uninstall APK
await sbx.adb_shell.uninstall("com.baidu.searchbox")
# Verify uninstallation
pmList = await 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")