> ## Documentation Index
> Fetch the complete documentation index at: https://docs.run.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# Launch and Terminate Apps

> Launch an installed app by bundle id or package name, and stop it, on iOS Simulator and Android Emulator sessions.

Start an installed app, or stop it, by its identifier: the iOS bundle id
(`CFBundleIdentifier`) or the Android package name. Both operations are
available on iOS Simulator and Android Emulator through the CLI, TypeScript
SDK, and REST API.

## Before you start

You need an active session that belongs to the authenticated account, and the
app must already be installed on that session. See
[Run an iOS simulator](https://docs.run.cloud/ios/run-simulator.md) or
[Run an Android emulator](https://docs.run.cloud/android/run-emulator.md) to create a session and install
an app.

For CI, the TypeScript SDK, or direct REST calls, create an API key in the
[dashboard](https://run.cloud/dashboard) and expose it to the process:

```bash theme={null}
export RUN_CLOUD_API_KEY="rc_live_..."
```

## Use the CLI

```bash iOS theme={null}
runcloud ios launch-app "$IOS_SESSION_ID" com.example.app --json
runcloud ios launch-app "$IOS_SESSION_ID" com.example.app \
  --arg=-FIRDebugEnabled --arg=--skip-onboarding --terminate-running --json
runcloud ios terminate-app "$IOS_SESSION_ID" com.example.app --json
```

```bash Android theme={null}
runcloud android launch-app "$ANDROID_SESSION_ID" com.example.app --json
runcloud android terminate-app "$ANDROID_SESSION_ID" com.example.app --json
```

Successful JSON names the session and the app:

```json theme={null}
{
  "ok": true,
  "platform": "ios",
  "sessionId": "sim_example",
  "bundleId": "com.example.app"
}
```

The acknowledgement confirms that the device accepted the launch or stop. To
assert the visible result, capture a screenshot or read the accessibility tree.

## Use the TypeScript SDK

`launchApp` and `terminateApp` need `@run-cloud/sdk` 0.68.0 or newer:

```ts theme={null}
import {
  Client,
  type SimulatorAppLaunchResult,
  type SimulatorAppTerminateResult,
} from "@run-cloud/sdk";

const cloud = new Client();

const launched: SimulatorAppLaunchResult = await cloud.ios.launchApp(
  process.env.IOS_SESSION_ID!,
  "com.example.app",
  { arguments: ["-FIRDebugEnabled"], terminateRunning: true },
);

const stopped: SimulatorAppTerminateResult = await cloud.android.terminateApp(
  process.env.ANDROID_SESSION_ID!,
  "com.example.app",
);
```

Both methods accept an `AbortSignal` as `signal`. When the platform is selected
at runtime, use the generic simulator client:

```ts theme={null}
await cloud.simulators.launchApp(session.id, "com.example.app", {
  platform: session.platform,
});
await cloud.simulators.terminateApp(session.id, "com.example.app", {
  platform: session.platform,
});
```

## Call the REST API

```text theme={null}
POST /run-cloud/{ios|android}/{sessionId}/apps/launch
POST /run-cloud/{ios|android}/{sessionId}/apps/terminate
```

| Field | Operation | Type | Description |
| - | - | - | - |
| `bundleId` | Both | `string` | iOS bundle id or Android package name. Required. |
| `arguments` | Launch | `string[]` | iOS only. At most 64 strings of at most 4 KB each. |
| `terminateRunning` | Launch | `boolean` | Stop the app first if it is already running. |

```bash theme={null}
curl --fail-with-body --silent --show-error \
  --request POST \
  --header "Authorization: Bearer $RUN_CLOUD_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{"bundleId":"com.example.app","terminateRunning":true}' \
  "https://api.run.cloud/run-cloud/ios/$IOS_SESSION_ID/apps/launch"
```

The response has the same four fields as SDK and CLI JSON output.

## Platform behavior

| Behavior | iOS Simulator | Android Emulator |
| - | - | - |
| Identifier | Bundle id, for example `com.example.app` | Package name, for example `com.example.app` |
| Launch arguments | Passed to the app process | Not supported; a non-empty list fails with `unsupported_argument` |

## Troubleshooting

Errors include `ok: false`, outer `action` (`"app-launch"` or
`"app-terminate"`), `platform`, `sessionId`, and a nested `error` object with
`code`, `message`, `retryable`, and `action`, the suggested next step.

| Code | HTTP | Retry? | What to do |
| - | - | - | - |
| `invalid_bundle_id` | 400 | No | Use a reverse-DNS identifier of at most 255 characters, such as `com.example.app`. |
| `invalid_launch_options` | 400 | No | Send `arguments` as at most 64 strings of at most 4 KB each, and `terminateRunning` as a boolean. |
| `unsupported_argument` | 400 | No | Remove `arguments` from an Android launch. |
| `active_session_not_found` | 404 | No | The session is inactive, belongs to another account, or is under the other platform. |
| `app_not_installed` | 404 | No | Install the app on this session, then retry. |
| `simulator_not_ready` | 409 | Yes | Wait for the device to finish booting, then retry. |
| `simulator_session_ended` | 410 | No | The session ended. Create a new session. |
| `app_lifecycle_unsupported` | 501 | No | This session cannot launch or stop apps yet. Create a new session, or open the app with a [URL or deep link](https://docs.run.cloud/platform/open-urls.md). |
| `simulator_unavailable` | 503 | Usually | The device is not available. Retry with a bounded backoff when `retryable` is true; otherwise create a new session. |
| `app_launch_timeout` or `app_terminate_timeout` | 504 | Yes | The device did not finish within 30 seconds. Check session state before retrying. |
| `app_launch_failed` or `app_terminate_failed` | 502 | Yes | Confirm the app is installed and the device is responsive, then retry. |
| `app_lifecycle_transport_error` or `app_lifecycle_invalid_response` | 502 | Yes | The request could not be completed or verified. Check session health before a bounded retry. |

SDK failures throw `RunCloudError` with `status`, `code`, `retryable`,
`platform`, `sessionId`, `action`, and `suggestedAction`. The
`SIMULATOR_APP_LIFECYCLE_ERROR_CODES` export lists the codes above.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.