Container Detection
Protection Module: ContainerDetection
Detects when the application is running inside containerized environments such as Docker, Kubernetes, LXC, Podman, or systemd-nspawn.
Available for: Linux (full), Windows (partial), macOS (limited), Mobile (N/A)
How It Works
The Container Detection module identifies when the application is running inside containerized environments by analyzing system indicators specific to different container runtimes and environment metadata. These environments are commonly used for automated testing, malware analysis, and unauthorized code execution.
Detection Techniques
- Docker Markers: Checks for
/.dockerenvfile and docker-specific cgroup paths - Cgroup Analysis: Identifies container control group signatures indicating Docker, LXC, Podman, or systemd-nspawn
- Kubernetes Detection: Identifies Kubernetes service account paths and environment variables (KUBERNETES_SERVICE_HOST, KUBERNETES_SERVICE_PORT, KUBERNETES_PORT)
- LXC/LXD Indicators: Detects LXC container markers in
/proc/1/cgroupand/run/systemd/containerfile - Podman Detection: Identifies Podman containers via
/proc/1/cgroupand/run/.containerenvfile - systemd-nspawn Detection: Detects systemd-nspawn environments via cgroup and container markers
- Environment Variable Analysis: Monitors for container-specific environment variables
- Hostname Detection: Identifies container-style hostnames and UUID-based naming patterns
Detection confidence: 0.9 | Default interval: 10 minutes (cached permanently)
Configuration
JSON Configuration
{
"protections": [
{
"type": "ContainerDetection",
"action": "log",
"intervalMs": 600000
}
]
}{
"protections": [
{
"type": "ContainerDetection",
"action": "log",
"intervalMs": 600000
}
]
}Kotlin Code-Based
import com.bytehide.monitor.Monitor
import com.bytehide.monitor.core.action.ActionType
import com.bytehide.monitor.core.protection.ProtectionModuleType
Monitor.configure { config ->
config.addProtection(
ProtectionModuleType.CONTAINER_DETECTION,
ActionType.LOG,
600000
)
}import com.bytehide.monitor.Monitor
import com.bytehide.monitor.core.action.ActionType
import com.bytehide.monitor.core.protection.ProtectionModuleType
Monitor.configure { config ->
config.addProtection(
ProtectionModuleType.CONTAINER_DETECTION,
ActionType.LOG,
600000
)
}Java Code-Based
import com.bytehide.monitor.Monitor;
import com.bytehide.monitor.core.action.ActionType;
import com.bytehide.monitor.core.protection.ProtectionModuleType;
Monitor.configure(config -> {
config.addProtection(
ProtectionModuleType.CONTAINER_DETECTION,
ActionType.LOG,
600000
);
});import com.bytehide.monitor.Monitor;
import com.bytehide.monitor.core.action.ActionType;
import com.bytehide.monitor.core.protection.ProtectionModuleType;
Monitor.configure(config -> {
config.addProtection(
ProtectionModuleType.CONTAINER_DETECTION,
ActionType.LOG,
600000
);
});Available Actions
| Action | Behavior | Recommended For |
|---|---|---|
| close | Terminate application immediately | Production apps with critical IP |
| log | Record incident and continue | Development, analytics |
| erase | Securely delete data then terminate | Financial, healthcare apps |
| custom | Execute custom handler | Enterprise integrations |
| none | Detect only, no action | Testing configurations |
See Actions for detailed action documentation.
When to Use
Enable Container Detection when:
- Protecting against automated abuse and bot farming
- Preventing large-scale security research and reverse engineering
- Detecting unauthorized execution environments
- Monitoring for infrastructure-level attacks
- Preventing containerized malware execution
- Enforcing real device usage policies
Code Examples
Kotlin - Basic Integration
import com.bytehide.monitor.Monitor
import com.bytehide.monitor.core.action.ActionType
import com.bytehide.monitor.core.protection.ProtectionModuleType
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Monitor.configure { config ->
config.addProtection(
ProtectionModuleType.CONTAINER_DETECTION,
ActionType.LOG,
600000
)
}
setContentView(R.layout.activity_main)
}
}import com.bytehide.monitor.Monitor
import com.bytehide.monitor.core.action.ActionType
import com.bytehide.monitor.core.protection.ProtectionModuleType
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Monitor.configure { config ->
config.addProtection(
ProtectionModuleType.CONTAINER_DETECTION,
ActionType.LOG,
600000
)
}
setContentView(R.layout.activity_main)
}
}Kotlin - Custom Action Handler
import com.bytehide.monitor.Monitor
import com.bytehide.monitor.core.protection.ProtectionModuleType
Monitor.configure { config ->
config.registerCustomAction("handle-container") { threat ->
val threatType = threat.getThreatType()
val description = threat.getDescription()
val confidence = threat.getConfidence()
val metadata = threat.getMetadata()
Log.e("Security", "Container detected: $threatType (confidence: $confidence)")
Log.e("Security", "Description: $description")
Log.e("Security", "Metadata: $metadata")
// Custom response: disable sensitive features, alert admin, etc.
disableSensitiveFeatures()
}
config.addProtection(
ProtectionModuleType.CONTAINER_DETECTION,
"handle-container",
600000
)
}
private fun disableSensitiveFeatures() {
// Disable payment processing, premium features, etc.
}import com.bytehide.monitor.Monitor
import com.bytehide.monitor.core.protection.ProtectionModuleType
Monitor.configure { config ->
config.registerCustomAction("handle-container") { threat ->
val threatType = threat.getThreatType()
val description = threat.getDescription()
val confidence = threat.getConfidence()
val metadata = threat.getMetadata()
Log.e("Security", "Container detected: $threatType (confidence: $confidence)")
Log.e("Security", "Description: $description")
Log.e("Security", "Metadata: $metadata")
// Custom response: disable sensitive features, alert admin, etc.
disableSensitiveFeatures()
}
config.addProtection(
ProtectionModuleType.CONTAINER_DETECTION,
"handle-container",
600000
)
}
private fun disableSensitiveFeatures() {
// Disable payment processing, premium features, etc.
}Java - Basic Integration
import com.bytehide.monitor.Monitor;
import com.bytehide.monitor.core.action.ActionType;
import com.bytehide.monitor.core.protection.ProtectionModuleType;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Monitor.configure(config -> {
config.addProtection(
ProtectionModuleType.CONTAINER_DETECTION,
ActionType.LOG,
600000
);
});
setContentView(R.layout.activity_main);
}
}import com.bytehide.monitor.Monitor;
import com.bytehide.monitor.core.action.ActionType;
import com.bytehide.monitor.core.protection.ProtectionModuleType;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Monitor.configure(config -> {
config.addProtection(
ProtectionModuleType.CONTAINER_DETECTION,
ActionType.LOG,
600000
);
});
setContentView(R.layout.activity_main);
}
}Java - Close Action (Production Security)
import com.bytehide.monitor.Monitor;
import com.bytehide.monitor.core.action.ActionType;
import com.bytehide.monitor.core.protection.ProtectionModuleType;
Monitor.configure(config -> {
config.addProtection(
ProtectionModuleType.CONTAINER_DETECTION,
ActionType.CLOSE,
600000
);
});import com.bytehide.monitor.Monitor;
import com.bytehide.monitor.core.action.ActionType;
import com.bytehide.monitor.core.protection.ProtectionModuleType;
Monitor.configure(config -> {
config.addProtection(
ProtectionModuleType.CONTAINER_DETECTION,
ActionType.CLOSE,
600000
);
});Platform Compatibility
| Platform | Status | Notes |
|---|---|---|
| Linux | ✓ Fully Supported | /proc analysis, cgroup detection, marker files |
| Windows | ✓ Partial | Environment variables, process detection |
| macOS | ✓ Limited | Process-based detection |
| Mobile (Android) | ✗ N/A | Not applicable on mobile platforms |
| Docker Engine | ✓ Detected | All Docker versions |
| Kubernetes | ✓ Detected | Service account path detection |
| LXC/LXD | ✓ Detected | Cgroup and marker file detection |
| Podman | ✓ Detected | Cgroup and .containerenv detection |
| systemd-nspawn | ✓ Detected | Cgroup and /run/systemd/container detection |
Performance Impact
- CPU Impact: < 1% during detection cycles
- Memory Overhead: ~300 KB for environment data caching
- Detection Latency: 100-200 ms per cycle
- Battery Impact: Minimal (low-frequency checks, cached permanently)
- Network Impact: None (purely local system analysis)
Threat Detection Details
{
"detection": {
"threatType": "Docker",
"timestamp": "2026-03-03T14:30:45.309Z",
"description": "Docker container environment detected via /.dockerenv marker and cgroup analysis",
"confidence": 0.9,
"metadata": {
"containerType": "docker",
"dockerenvExists": true,
"cgroupPath": "/docker/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6",
"containerId": "a1b2c3d4e5f6",
"hostname": "a1b2c3d4e5f6",
"detectionMethod": "marker_and_cgroup_analysis",
"indicators": ["/.dockerenv", "docker", "/docker/", "DOCKER_HOST"]
}
}
}{
"detection": {
"threatType": "Docker",
"timestamp": "2026-03-03T14:30:45.309Z",
"description": "Docker container environment detected via /.dockerenv marker and cgroup analysis",
"confidence": 0.9,
"metadata": {
"containerType": "docker",
"dockerenvExists": true,
"cgroupPath": "/docker/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6",
"containerId": "a1b2c3d4e5f6",
"hostname": "a1b2c3d4e5f6",
"detectionMethod": "marker_and_cgroup_analysis",
"indicators": ["/.dockerenv", "docker", "/docker/", "DOCKER_HOST"]
}
}
}Another detection example (Kubernetes):
{
"detection": {
"threatType": "Kubernetes",
"timestamp": "2026-03-03T14:30:45.309Z",
"description": "Kubernetes environment detected via service account path and environment variables",
"confidence": 0.9,
"metadata": {
"containerType": "kubernetes",
"serviceAccountPath": "/var/run/secrets/kubernetes.io/serviceaccount",
"kubernetesPod": true,
"namespace": "default",
"podName": "app-deployment-5d4c8b7a9",
"clusterDomain": "cluster.local",
"detectionMethod": "service_account_path_and_env_vars",
"indicators": ["KUBERNETES_SERVICE_HOST", "KUBERNETES_SERVICE_PORT", "/var/run/secrets/kubernetes.io"]
}
}
}{
"detection": {
"threatType": "Kubernetes",
"timestamp": "2026-03-03T14:30:45.309Z",
"description": "Kubernetes environment detected via service account path and environment variables",
"confidence": 0.9,
"metadata": {
"containerType": "kubernetes",
"serviceAccountPath": "/var/run/secrets/kubernetes.io/serviceaccount",
"kubernetesPod": true,
"namespace": "default",
"podName": "app-deployment-5d4c8b7a9",
"clusterDomain": "cluster.local",
"detectionMethod": "service_account_path_and_env_vars",
"indicators": ["KUBERNETES_SERVICE_HOST", "KUBERNETES_SERVICE_PORT", "/var/run/secrets/kubernetes.io"]
}
}
}