CubeSandbox Security Isolation Guarantees Against Malicious LLM-Generated Code

CubeSandbox implements a defense-in-depth architecture that isolates malicious LLM-generated code through hardware-level KVM MicroVMs, eBPF-based network segregation, application-layer egress filtering, and strict seccomp system call confinement.

TencentCloud/CubeSandbox provides a production-grade sandboxing solution designed specifically to execute untrusted code produced by large language models. The platform guarantees that even actively malicious code cannot escape containment, access host resources, or exfiltrate sensitive data through multiple independent security layers enforced automatically at runtime.

Hardware Isolation via KVM MicroVMs

Each sandbox executes inside its own KVM MicroVM with a dedicated Linux kernel instance. This eliminates shared-kernel attack surfaces that traditional container-based sandboxes expose.

According to the architecture documentation in docs/architecture/overview.md, the hardware isolation layer ensures that kernel-level exploits, privilege escalation attempts, or container escape vulnerabilities in one sandbox cannot affect the host or neighboring sandboxes. The MicroVM boots with a minimal, hardened kernel image managed by the CubeHypervisor Rust component, providing true hardware virtualization boundaries rather than software-based isolation.

Network Isolation with CubeVS

CubeSandbox enforces per-sandbox network segregation through CubeVS, an eBPF-based virtual switch that manages traffic between MicroVMs and the external network.

As documented in docs/architecture/network.md and implemented in the CubeNet/cubevs/ directory, each sandbox receives a dedicated TAP device. The eBPF programs attach to these interfaces and enforce default-deny policies for private and link-local IP ranges. Traffic between sandboxes is explicitly blocked at the virtual switch layer, preventing lateral movement even if multiple malicious LLM-generated code instances run simultaneously.

Application-Level Egress Control

All outbound HTTP/HTTPS traffic must traverse CubeEgress, a transparent L7 proxy that performs domain, method, and path filtering. This layer prevents data exfiltration and unauthorized API calls.

The egress control implementation, described in docs/architecture/overview.md, operates as a man-in-the-middle proxy that inspects every outgoing request. The proxy maintains an allowlist of permissible domains and injects authentication headers only at the proxy layer, ensuring that secrets never reach the sandbox environment where LLM-generated code could read them.

Credential Vault Protection

Secrets and API keys are stored in a credential vault completely outside the sandbox boundary. When LLM-generated code requires authenticated access to external services, the CubeEgress proxy injects the necessary credentials as HTTP headers.

This architecture ensures that even if malicious code attempts to read environment variables or scan memory for tokens, it cannot access the actual secrets. The credential vault integration is referenced in the security layer documentation within docs/architecture/overview.md.

Seccomp System Call Confinement

CubeSandbox generates minimal seccomp profiles that whitelist only the specific system calls required for each sandbox. Any syscall not explicitly permitted results in immediate process termination.

The seccomp profile generation logic resides in Cubelet/pkg/container/seccomp/seccomp.go. The GenOpt function builds the final whitelist by combining a default minimal profile with additional syscalls specified in the SysCall protobuf definition. This prevents malicious code from invoking dangerous kernel interfaces like execve, ptrace, or unauthorized network socket operations.

Authentication and Authorization

The CubeAPI service validates all requests before forwarding them to the control plane, ensuring that only authorized users can create, modify, or inspect sandboxes. Implemented in Rust, the authentication hooks verify bearer tokens and enforce role-based access controls as part of the request lifecycle.

This prevents unauthorized sandbox creation that could be used to amplify attacks or consume resources.

Stateless Control Plane Architecture

All sandbox metadata persists in Redis rather than on the host filesystem or within the sandbox itself. This stateless design means that a compromised MicroVM cannot tamper with the control plane state or persist malicious configurations across sessions.

The separation between control plane (CubeMaster) and data plane (sandbox execution) is documented in the "Control Plane vs Data Plane" section of docs/architecture/overview.md.

Implementing Isolation in Code

The following examples demonstrate how CubeSandbox automatically applies these security guarantees when executing LLM-generated code.

Python SDK Execution

The Python SDK transparently enforces all isolation layers without requiring explicit security configuration:

from cubesandbox import Sandbox, Config

cfg = Config(
    api_url="https://my.cubesandbox.instance",
    auth_token="my-secret-token"
)

# Create a sandbox with automatic hardware isolation and seccomp profiles

sb = Sandbox.create("python-3.10", config=cfg)

# Execute untrusted LLM-generated code

result = sb.run_code(
    """
import os, socket
print(os.listdir('/'))          # Limited to sandbox rootfs only

print(socket.getaddrinfo('example.com', 80))  # Filtered through CubeEgress

""",
    timeout=30
)

print(result.stdout)

In this example, the code runs inside a KVM MicroVM with network traffic routed through the eBPF-based CubeVS TAP interface and filtered by the CubeEgress proxy. The seccomp profile is generated automatically from the template and applied by the hypervisor.

Go SDK and Custom Seccomp Profiles

For scenarios requiring additional system calls, the Go SDK allows explicit syscall declarations that the seccomp generator incorporates into the whitelist:

import (
    "context"
    cs "github.com/tencentcloud/CubeSandbox/sdk/go"
    sbpb "github.com/tencentcloud/CubeSandbox/Cubelet/api/services/cubebox/v1"
)

func main() {
    client := cs.NewClient(cs.NewConfigFromEnv())
    sandbox, _ := client.Create(context.Background(), cs.CreateOptions{
        Template: "go-1.22",
        Syscalls: []*sbpb.SysCall{
            {
                Names: []string{"socket"},
                Action: sbpb.SysCall_ALLOW,
            },
        },
    })
    // Sandbox executes with hardware isolation plus explicit socket syscall permission
}

The GenOpt function in Cubelet/pkg/container/seccomp/seccomp.go merges these custom syscalls into the default profile, ensuring that only the explicitly permitted socket syscall is available to the sandboxed process.

Core Implementation Files

The security guarantees are implemented across these key components:

Component Source Location Security Function
Hardware Isolation CubeHypervisor (Rust VMM driver) Launches dedicated KVM MicroVM per sandbox
Network Segregation CubeNet/cubevs/* (eBPF programs) TAP device management and traffic filtering
Egress Proxy CubeEgress/* (OpenResty Lua) Domain filtering and credential injection
Seccomp Engine Cubelet/pkg/container/seccomp/seccomp.go Syscall whitelist generation via GenOpt
Control Plane CubeMaster/* and Redis coordination State management and sandbox lifecycle
Architecture Docs docs/architecture/overview.md Security model documentation

Summary

CubeSandbox provides comprehensive security isolation guarantees against malicious LLM-generated code through:

  • Hardware virtualization using dedicated KVM MicroVMs that eliminate shared-kernel attack surfaces
  • eBPF-based network isolation via CubeVS that enforces per-sandbox traffic policies and prevents lateral movement
  • Application-layer egress filtering through CubeEgress, which controls outbound domains and injects credentials externally
  • System call confinement using auto-generated seccomp profiles that whitelist only necessary syscalls
  • Stateless architecture that prevents persistent tampering with control plane metadata

These layers operate automatically when using the Python or Go SDKs, requiring no additional security configuration from developers.

Frequently Asked Questions

How does CubeSandbox prevent container escape attacks?

CubeSandbox eliminates container escape vulnerabilities by using KVM MicroVMs rather than traditional containers. Each sandbox runs with its own dedicated Linux kernel instance launched by the CubeHypervisor, as documented in docs/architecture/overview.md. This hardware-level isolation means that even kernel-level exploits within the sandbox cannot affect the host or other sandboxes, as there is no shared kernel namespace to escape from.

Can LLM-generated code access my API keys or secrets?

No. CubeSandbox implements a credential vault architecture where secrets remain outside the sandbox environment. The CubeEgress proxy injects authentication headers only after filtering outbound requests, ensuring that LLM-generated code executing inside the MicroVM cannot read environment variables, memory, or filesystem locations containing sensitive tokens. This design prevents credential theft even if the code attempts to scan for secrets.

What happens if malicious code tries to make unauthorized system calls?

Unauthorized system calls are blocked by seccomp enforcement. The GenOpt function in Cubelet/pkg/container/seccomp/seccomp.go generates a minimal whitelist of permitted syscalls based on the sandbox template and explicit SysCall protobuf declarations. Any attempt to invoke non-whitelisted syscalls results in immediate process termination, preventing dangerous operations like ptrace, mount, or unauthorized process creation.

How does network isolation work between multiple sandboxes?

Network isolation is enforced by CubeVS, an eBPF-based virtual switch that creates dedicated TAP devices for each sandbox. According to docs/architecture/network.md, the eBPF programs attached to these interfaces implement default-deny policies for private IP ranges and explicitly block inter-sandbox traffic. This ensures that even if multiple instances of malicious LLM-generated code run simultaneously, they cannot communicate with each other or scan internal network resources.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →