This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
dstack is a developer-friendly, security-first framwwork for deploying containerized applications into Intel TDX (Trust Domain Extensions) Trusted Execution Environments (TEEs). The system provides end-to-end security through hardware-rooted attestation, automated key management, and zero-trust networking.
dstack consists of several core components that interact to provide TEE-based container deployment:
-
dstack-vmm(vmm/): Virtual Machine Manager that runs on bare-metal TDX hosts. Orchestrates CVM lifecycle, manages QEMU processes, allocates resources, parses docker-compose files, and provides a web UI (port 9080) for deployment. -
dstack-kms(kms/): Key Management System that handles cryptographic key provisioning after TDX quote verification. Derives keys deterministically per application identity and enforces authorization policies defined in smart contracts on Ethereum. -
dstack-gateway(gateway/): Reverse proxy providing zero-trust network access. Handles TLS termination, automated ACME certificate provisioning, and traffic routing via ingress mapping rules. -
dstack-guest-agent(guest-agent/): Runs inside each CVM to provide runtime services including Docker Compose lifecycle management, TDX quote generation, key provisioning from KMS, and log aggregation. Exposes API via Unix socket at/var/run/dstack.sock.
- RA-TLS: Remote Attestation TLS used for all inter-CVM communication, embedding TDX quotes in X.509 certificates for mutual authentication
prpc: Protocol Buffers-based RPC framework used across all service APIsvsock: Host-guest communication channel for metadata and configuration- Unix Domain Sockets: Used for local management (e.g.,
vmm.sock)
certbot(certbot/): Automated ACME DNS-01 certificate managementct_monitor(ct_monitor/): Certificate Transparency log monitoringverifier(verifier/): TDX quote verification service usingdcap-qvlsupervisor(supervisor/): Process supervision inside CVMs- SDKs (
sdk/): Client SDKs in Rust, Python, Go, and JavaScript for interacting with guest-agent APIs
# Build all components
cargo build --release
# Build specific components
cargo build --release -p dstack-vmm
cargo build --release -p dstack-kms
cargo build --release -p dstack-gateway
cargo build --release -p dstack-guest-agent
# Check code
cargo check --all-features
# Format code
cargo fmt --all
# Lint with Clippy
cargo clippy -- -D warnings --allow unused_variablescd kms/auth-eth
npm install
npm run build # Compile TypeScript
npm test # Run tests
npm run test:coverage # Run tests with coverage
# Hardhat commands
npx hardhat compile
npx hardhat test
npx hardhat node # Start local nodecd sdk/python
make install # Install dependencies
make test # Run tests# Run all Rust tests (requires simulator)
./run-tests.shThis script:
- Builds the SDK simulator (
sdk/simulator/) - Starts the simulator in background
- Sets
DSTACK_SIMULATOR_ENDPOINTandTAPPD_SIMULATOR_ENDPOINT - Runs
cargo test --all-features -- --show-output
# Run tests for a specific package
cargo test -p dstack-kms --all-features
# Run a specific test
cargo test --all-features test_name
# Run tests with output
cargo test --all-features -- --show-output --test-threads=1cd kms/auth-eth
# Run all Foundry tests
forge test
# Run with verbosity
forge test -vv
# Run specific test contract
forge test --match-contract UpgradesWithPluginTest -vv
# Clean build artifacts
forge clean- Never capitalize the first letter of log messages and error messages
- Example:
log::info!("starting server on port {}", port); - Example:
anyhow::bail!("failed to connect to server");
This rule is enforced in .cursorrules.
- Quote Generation: Applications request TDX quotes via
getQuote()with reportData (up to 64 bytes) - Quote Verification:
dstack-verifiervalidates quotes usingdcap-qvl, verifies OS image hash, and replays RTMRs from event logs - RTMR Replay: Compute Runtime Measurement Register values by applying SHA384 hashing to event log entries
- Deterministic Keys:
getKey(path, purpose)derives secp256k1 keys using HKDF, with signature chains proving TEE origin - TLS Keys:
getTlsKey()generates fresh X.509 certificates with optional RA-TLS support - Environment Encryption: Client-side encryption using X25519 ECDH + AES-256-GCM, decrypted only in TEE
- DstackKms: Main KMS contract managing OS image whitelist and app registration
- DstackApp: Per-app authorization contract controlling device IDs and compose hash whitelist
- Deployed on Ethereum-compatible networks (Phala Network)
- Build meta-dstack artifacts (see README.md section "Build and Run")
- Download or build guest OS image
- Run components in separate terminals:
- KMS:
./dstack-kms -c kms.toml - Gateway:
sudo ./dstack-gateway -c gateway.toml - VMM:
./dstack-vmm -c vmm.toml
- KMS:
- Via Web UI:
http://localhost:9080(or configured port) - Via CLI:
./vmm-cli.py(seedocs/vmm-cli-user-guide.md) - Requires:
- On-chain app registration (
npx hardhat kms:create-app) - Adding compose hash to whitelist (
npx hardhat app:add-hash) - Deploying via VMM with App ID
- On-chain app registration (
Ingress mapping pattern: <id>[-[<port>][s|g]].<base_domain>
- Default: TLS termination to TCP
ssuffix: TLS passthroughgsuffix: HTTP/2 with TLS termination (gRPC)
Cargo.toml: Workspace configuration with all Rust cratesvmm.toml: VMM configuration (CID pool, port mapping, KMS/gateway URLs)kms.toml: KMS configuration (contract addresses, RPC endpoints)gateway.toml: Gateway configuration (domain, certificates, WireGuard)docker-compose.yaml: App deployment format (normalized to.app-compose.json)
- Create crate directory and
Cargo.toml - Add to workspace members in root
Cargo.toml - Add workspace dependency if it will be used by other crates
RPC definitions use prpc framework with Protocol Buffers:
- Define
.protofiles in*/rpc/proto/ - Use
prpc-buildinbuild.rsto generate Rust code - Implement service traits in main crate
- Pure Rust API:
tdx-attest/ - Verification:
verifier/usingdcap-qvl - Event log parsing:
cc-eventlog/
- Main README:
README.md - Deployment guide:
docs/deployment.md - VMM CLI guide:
docs/vmm-cli-user-guide.md - Security guide:
docs/security-guide/security-guide.md - Design decisions:
docs/design-and-hardening-decisions.md
When need more detailed info, try to use deepwiki mcp.
The .agent/ directory contains AI assistant resources:
WRITING_GUIDE.md— Documentation and README writing guidelines (messaging, style, audiences)GPU_TEE_DEPLOYMENT.md— GPU deployment to Phala Cloud (instance types, docker-compose config, debugging)