HarmonyOS PC App Sandbox vs Non-Sandbox Environments: HiShell, hdc shell, and Permission Boundaries Explained

The terminal on HarmonyOS PC does not inherently grant system-level privileges. HiShell runs inside the application sandbox and is jointly constrained by namespaces, UID, SELinux, and seccomp; hdc shell can escape the app sandbox, but it is still not root by default. This article explains the visibility and permission boundaries of both environments. Keywords: HarmonyOS PC, application sandbox, hdc shell

Technical Specification Snapshot

Parameter Description
Technical topic Isolation in HarmonyOS PC low-level development environments
Related systems HarmonyOS / OpenHarmony
Core mechanisms mnt namespace, pid namespace, SELinux, seccomp
Typical terminals HiShell, hdc shell
Default identity App UID / shell UID
Source article profile Original technical blog post on CSDN
Star count Not provided in the original article
Core dependencies Linux namespaces, the appspawn application spawner, the hdcd debugging service

HiShell runs inside the application sandbox by design

After HarmonyOS inherited the OpenHarmony application model, each app runs in an isolated sandbox by default. This sandbox is not an abstract concept. It is a real isolation environment implemented through Linux namespace mechanisms.

When you open HiShell on a HarmonyOS PC, what you see is the internal world of a terminal app, not the full host system. Any zsh session, command-line tool, or script started from it inherits the same isolation boundary.

PID 1 -> appspawn -> com.huawei.hmos.hishell -> zsh

This process chain shows that HiShell is not a shell launched directly by the system. Instead, appspawn creates it as the application spawner, so it naturally runs inside the app sandbox.

appspawn determines sandbox inheritance

When appspawn forks an application process, it injects namespaces and security attributes. Because Linux processes inherit the parent process environment by default, child processes started from HiShell usually cannot break out of the existing isolation boundary.

This means many issues developers encounter in HiShell are not tool failures. They happen because the runtime context is intentionally designed as a restricted application environment.

ps -ef | grep -E 'appspawn|hishell|zsh'  # Inspect the key process chain
id                                        # Check the identity assigned to the current app
pwd                                       # Observe the currently accessible directory

These commands help confirm that you are in an application context rather than a full host shell.

The application sandbox limits both visibility and operability

At minimum, an application sandbox answers two questions: what a process can see, and what it can do. The first is mainly determined by namespaces and mount points. The second is mainly controlled by UID, SELinux, and seccomp.

In low-level HarmonyOS PC development, the most common misconception is assuming that entering a terminal gives you the freedom of a traditional Linux development environment. In reality, HiShell behaves more like a controlled container than an administrator console.

Four categories of restrictions form the real boundary

First, mount-point isolation often maps directories such as /bin and /lib into the sandbox as read-only or otherwise controlled views. The system layout you can see may not be a complete view of the physical root filesystem.

Second, the app-centric UID model gives different applications different identities. The user ID you see in HiShell may differ from the one used in CodeArts IDE, and file ownership and process privileges change accordingly.

Third, SELinux determines that having nominal permission does not necessarily mean access will succeed. Even if file mode bits allow an operation, the system can still deny I/O, execution, or inter-process actions when security labels do not match.

mount        # May fail because of permissions or policy restrictions
chroot /tmp  # Commonly unavailable in typical scenarios
chown a:b x  # Constrained by identity and security policy

These failures usually do not mean the commands are incorrect. They are normal results of sandbox policy enforcement.

Fourth, seccomp filters high-risk syscalls. Some debuggers, runtimes, or ported software that depend on low-level system calls can fail outright in this environment.

These restrictions directly affect command-line application porting

For low-level developers, the issue is not simply missing a few permissions. Many classic Unix assumptions no longer hold inside the HarmonyOS application sandbox.

For example, a program may assume the presence of /tmp, a complete Filesystem Hierarchy Standard layout, a real user database, mutable mount points, or a valid sudo privilege-escalation path. In HiShell, these conditions are often incomplete or unavailable.

Typical failure patterns can be diagnosed in advance

  • Interfaces such as getpwuid, setfsuid, mount, and chroot may behave unexpectedly.
  • Debugging tools may fail because required syscalls are blocked.
  • User identity and file ownership may not match, causing initialization failures.
  • A directory may be visible but still unwritable because it is mounted read-only.
  • Software that depends on standard directories such as /tmp may not work directly.
  • sudo in HiShell cannot actually elevate to root.
import os
import tempfile

print(os.getuid())  # Print the current process UID to identify the privilege boundary
print(os.getcwd())  # Print the working directory to inspect the available runtime environment
print(tempfile.gettempdir())  # Check whether the temporary directory matches software expectations

This code quickly probes identity and filesystem compatibility inside the application sandbox.

hdc shell can leave the application sandbox but remains privilege-constrained

If you do not enter a terminal from inside an app and instead connect through the device debugging channel, such as hdc shell, the runtime context changes.

In this case, the shell is not launched by appspawn under the application model. It is created directly by the system debugging service hdcd, so it usually runs outside the application sandbox.

PID 1 -> hdcd -> sh

This chain shows that sh inherits the debugging service context rather than the context of an application container. As a result, it can usually see a filesystem state much closer to the real host system.

Non-sandbox does not mean root

When many developers first use hdc shell, they assume they already have full control. In reality, this only changes the spatial dimension of isolation. It does not guarantee a matching privilege increase.

A more accurate evaluation framework is:

  • Non-sandbox: whether you can see the real physical root filesystem.
  • Root: whether you can perform protected operations as UID 0.
whoami      # Determine whether the current identity is shell or root
id          # Verify whether the UID is 0
ls /        # Observe whether the full system directory tree is accessible

These commands distinguish between two very different capabilities: seeing the system and modifying the system.

Full control requires two conditions at the same time

On commercial HarmonyOS PC devices, the shell launched by hdcd is usually just the low-privilege shell user. You may be able to see the complete directory tree, but you still cannot modify system configuration, mount filesystems, or operate on protected device nodes.

Therefore, freedom in low-level debugging cannot be judged solely by whether you have escaped the app sandbox. You must also confirm whether you have obtained root identity. If either condition is missing, you do not have a fully privileged environment.

Community OpenHarmony devices are usually better suited for low-level debugging

On community devices intended for driver, kernel, and system development, debugging images often expose higher privileges by default. If hdcd runs as root in that setup, the shell it launches gains both capabilities at once: non-sandbox access and root privileges.

This is why low-level development experience can vary dramatically across devices in the OpenHarmony ecosystem. The difference is not in the commands themselves. It is in the runtime security model and image policy.

FAQ

Why do many Linux commands behave abnormally in HiShell?

Because HiShell belongs to the application sandbox. Commands inherit restricted namespaces, an app-specific UID, SELinux policy, and seccomp filtering, so their behavior is not equivalent to a normal Linux host terminal.

If hdc shell is already outside the sandbox, why can it still not run mount?

Because leaving the application sandbox only means you can see a more realistic system space. It does not mean you have root privileges. If your current identity is still the shell user, core system operations are still denied.

How can I determine whether the current environment is suitable for low-level debugging?

First, inspect the process origin, then check the UID. If the chain is appspawn -> app -> shell, you are effectively inside the application sandbox. If the chain is hdcd -> sh, you are usually outside the sandbox. Then use id to verify whether the UID is 0. Only a non-sandbox environment with root privileges is suitable for full low-level debugging.

AI Readability Summary

This article systematically explains the essential differences between application-sandboxed and non-application-sandboxed environments on HarmonyOS PC. It focuses on the process origins of HiShell and hdc shell, namespace isolation, UID behavior, and the restrictions imposed by SELinux and seccomp, helping developers determine the real boundaries of what they can see and what they can do.