On Android >= 10, SELinux policies prevent untrusted_app* domains from executing files located in app data directories (e.g., /data/data/<package_name>) due to W^X (Write XOR Execute) restrictions.
To bypass this, you can use the system dynamic linker to execute the file. Because the kernel/SELinux sees the system_linker_exec context of the linker rather than the app_data_file context of your binary, execution is permitted.
Executing an ELF Binary
To execute a 64-bit ELF binary located in your app data directory:
/system/bin/linker64 /data/data/com.foo/executable [args]
Executing a Script
To execute a script with a shebang (e.g., #!/path/to/interpreter):
/system/bin/linker64 /path/to/interpreter /data/data/com.foo/script.sh [args]
Note: This method requires Android 10 or higher.
# Example: Executing an ELF binary via the system linker
/system/bin/linker64 /data/data/com.foo/executable [args]
# Example: Executing a script via the system linker
/system/bin/linker64 /path/to/interpreter /data/data/com.foo/script.sh [args]