Lybic Docs

Apk Installation in Android Sandbox

Due to timeout limitations in Lybic's download API and command execution API, you may not be able to install large APK files using these APIs.

However, you can generally install APK files using the following pseudocode process:

  1. Download and install the script in batches.
#!/system/bin/sh
# If URLs are provided:
curl downloads one or more APKs -> APKs are stored in a temporary directory
pm install installs these downloaded APKs
rm deletes these APK files

# If an Android directory on the Android device is provided:
pm install installs these APKs but does not delete the APK files
  1. Running with nohup

nohup allows commands to run in the background, preventing timeout issues. You can run the script using the following command format:

sh -c nohup sh -c {shell_scripts} >/dev/null 2>&1 &

Refer to the API for executing commands.

curl -X POST "https://api.Lybic.cn/api/orgs/{orgId}/sandboxes/{sandboxId}/process" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"executable": "sh",
"args": ["-c", "nohup sh -c '{script_content}' >/dev/null 2>&1 &"]
}'
import asyncio
import base64
from Lybic import LybicClient, LybicAuth

async def main():
  async with LybicClient(
    LybicAuth(
    org_id="ORG-xxxx",
    api_key="lysk-xxxxxxxxxxx",
    endpoint="https://api.Lybic.cn/"
    )
  ) as client:
    await client.sandbox.execute_process(
      "SBX-xxxx",
      executable="sh",
      args=["-c", f"nohup sh -c '{script_content}' >/dev/null 2>&1 &"]
    )

if __name__ == "__main__":
asyncio.run(main())
import { LybicClient } from '@Lybic/core'

const Lybic = new LybicClient({
baseUrl: 'https://api.Lybic.cn',
orgId: 'ORG-xxxx',
apiKey: 'lysk-your-api-key-here',
})

const result = await Lybic.execSandboxProcess('SBX-xxxx', {
executable: 'sh',
args: ["-c", "nohup sh -c '{script_content}' >/dev/null 2>&1 &"]
})
package main

import (
"context"
"encoding/base64"
"fmt"

"github.com/Lybic/Lybic-sdk-go"
)

func main() {
ctx := context.Background()
client, _ := Lybic.NewClient(nil)

processDto := Lybic.SandboxProcessRequestDto{
Executable: "sh",
Args: []string{"-c", "nohup sh -c '{script_content}' >/dev/null 2>&1 &"},
}

result, err := client.ExecSandboxProcess(ctx, "SBX-xxxx", processDto)
if err != nil {
fmt.Println("exec process failed:", err)
return
}
}

If you are using the Python SDK, we provide a convenient method install_apk for installing APK files:

import asyncio
from lybic import LybicClient, LybicAuth, dto

async def install_apk_example():
    async with LybicClient(
        LybicAuth(
            org_id="ORG-xxxx",
            api_key="lysk-xxxxxxxxxxx",
            endpoint="https://api.lybic.cn/"
        )
    ) as client:
        # Example 1: Install APK from URL
        await client.tools.mobile_use.install_apk(
            sandbox_id="SBX-xxxx",
            app_sources=[
                dto.HttpRemote(url_path="https://example.com/app.apk")
            ]
        )
        print("APK installation started (running in background)")

        # Example 2: Install multiple APKs from URLs with custom headers
        await client.tools.mobile_use.install_apk(
            sandbox_id="SBX-xxxx",
            app_sources=[
                dto.HttpRemote(
                    url_path="https://example.com/app1.apk",
                    headers={"Authorization": "Bearer token"}
                ),
                dto.HttpRemote(
                    url_path="https://example.com/app2.apk",
                    headers={"User-Agent": "CustomAgent/1.0"}
                )
            ]
        )
        print("Multiple APKs installation started")

        # Example 3: Install APK from local path
        await client.tools.mobile_use.install_apk(
            sandbox_id="SBX-xxxx",
            app_sources=[
                dto.AndroidLocal(apk_path="/data/local/tmp/app.apk")
            ]
        )
        print("Local APK installation started")

        # Example 4: Mix local and remote APKs
        await client.tools.mobile_use.install_apk(
            sandbox_id="SBX-xxxx",
            app_sources=[
                dto.HttpRemote(url_path="https://example.com/app.apk"),
                dto.AndroidLocal(apk_path="/sdcard/Download/local.apk")
            ]
        )
        print("Mixed APK installation started")

if __name__ == '__main__':
    asyncio.run(install_apk_example())

Refer to

Python SDK

On this page