dstack Examples

April 15, 2026 · View on GitHub

GitHub Stars License Telegram Documentation

Example applications for dstack - Deploy containerized apps to TEEs with end-to-end security in minutes

Getting StartedConfidential AIUse CasesCore PatternsInfrastructureDev ToolsStarter PacksOther Use Cases


Overview

This repository contains ready-to-deploy examples demonstrating how to build and run applications on dstack, the developer-friendly SDK for deploying containerized apps in Trusted Execution Environments (TEE).

Getting Started

Prerequisites

  • Docker and Docker Compose
  • Node.js (for Phala CLI)
  • Git

Setup

# Clone the repo
git clone https://github.com/Dstack-TEE/dstack-examples.git
cd dstack-examples

# Install Phala CLI
npm install -g phala

# Start the local simulator (no TEE hardware needed)
phala simulator start

Run an Example Locally

cd tutorial/01-attestation-oracle
docker compose run --rm \
  -v ~/.phala-cloud/simulator/0.5.3/dstack.sock:/var/run/dstack.sock \
  app

Deploy to Phala Cloud

phala auth login
phala deploy -n my-app -c docker-compose.yaml

See Phala Cloud for production TEE deployment.


Confidential AI

Run AI workloads where prompts, model weights, and inference stay encrypted in hardware.

ExampleDescription
confidential-ai/inferencePrivate LLM inference with vLLM on Confidential GPU
confidential-ai/trainingConfidential fine-tuning on sensitive data using Unsloth
confidential-ai/agentsSecure AI agent with TEE-derived wallet keys using LangChain and Confidential AI models

GPU deployments require: --instance-type h200.small --region US-EAST-1 --image dstack-nvidia-dev-0.5.4.1

See Confidential AI Guide for concepts and security model.


Tutorials

Step-by-step guides covering core dstack concepts.

TutorialDescription
01-attestation-oracleUse the guest SDK to work with attestations directly — build an oracle, bind data to TDX quotes via report_data, verify with local scripts
02-persistence-and-kmsUse getKey() for deterministic key derivation from a KMS — persistent wallets, same key across restarts
03-gateway-and-ingressCustom domains with automatic SSL, certificate evidence chain
04-upgradesExtend AppAuth.sol with custom authorization logic — NFT-gated clusters, on-chain governance

Use Cases

Real-world applications you can build with dstack.

ExampleDescriptionStatus
8004-agentTrustless AI agent with on-chain attestation and LLM accessComing Soon
oracleTEE oracle returning JSON + signature + attestation bundleComing Soon
mcp-serverAttested MCP tool server behind gatewayComing Soon
telegram-agentTelegram bot with TEE wallet and verified executionComing Soon

Core Patterns

Key building blocks for dstack applications.

Attestation

Request TEE attestations via the SDK. Mount /var/run/dstack.sock in your compose file to access the TEE.

import { DstackClient } from '@phala/dstack-sdk'
const client = new DstackClient()
const info = await client.info()              // app_id, instance_id, tcb_info
const quote = await client.getQuote(data)     // TDX quote with custom report_data
const key = await client.getKey('/my/path')   // deterministic key derivation
volumes:
  - /var/run/dstack.sock:/var/run/dstack.sock
ExampleDescriptionStatus
timelock-ntsRaw socket usage (what the SDK wraps)Available
attestation/configid-basedConfigID-based verificationAvailable

Gateway & Domains

TLS termination, custom domains, external connectivity.

ExampleDescription
dstack-ingressComplete ingress solution — auto SSL via Let's Encrypt, multi-domain, DNS validation, evidence generation with TDX quote chain
custom-domainSimpler custom domain setup via zt-https

Keys & Persistence

Persistent keys across deployments via KMS.

ExampleDescriptionStatus
get-key-basicdstack.get_key() — same key identity across machinesComing Soon

On-Chain Interaction

Light client for reading chain state, anchoring outputs.

ExampleDescription
lightclientEthereum light client (Helios) running in enclave

Dev Scaffolding

Development and debugging tools. Not for production.

ExampleDescription
webshellWeb-based shell access for debugging
ssh-over-gatewaySSH tunneling through dstack gateway
tcp-port-forwardingArbitrary TCP port forwarding

Infrastructure

Run infrastructure services inside TEEs.

ExampleDescription
k3sSingle-node k3s cluster in a TEE with wildcard HTTPS and remote kubectl

Tech Demos

Interesting demonstrations.

ExampleDescription
tor-hidden-serviceRun Tor hidden services in TEEs

Starter Packs

Full-stack templates with SDK integration. These demonstrate attestation, key derivation, and wallet generation.

TemplateStackLink
Next.js StarterNext.js + TypeScriptphala-cloud-nextjs-starter
Python StarterFastAPI + Pythonphala-cloud-python-starter
Bun StarterBun + TypeScriptphala-cloud-bun-starter
Node.js StarterExpress + TypeScriptphala-cloud-node-starter

Features: /api/tdx_quote (attestation), /api/eth_account (derived wallet), /api/info (TCB info)


Other Use Cases

External projects and templates worth exploring. These are maintained elsewhere but demonstrate interesting TEE patterns.

ProjectDescriptionLink
Oracle TemplatePrice aggregator with verifiable networking (hardened TLS) and multi-source validationGldywn/phala-cloud-oracle-template
VRF TemplateVerifiable Random Function — hardware-backed cryptographic randomnessPhala-Network/phala-cloud-vrf-template
Open WebUISelf-hosted AI chat interface in TEEphala-cloud/templates/openwebui
n8n AutomationWorkflow automation (400+ integrations) with OAuth in TEEMarvin-Cypher/phala-n8n-template
Primus AttestorzkTLS node — TEE + zero-knowledge proofsprimus-labs/primus-network-startup
NEAR Shade AgentBlockchain oracle/agent for NEAR with TEE attestationphala-cloud/templates/near-shade-agent
PresidioMicrosoft's PII de-identification running in TEEHashWarlock/presidio
ByteBotAI desktop agent — computer control in isolated TEE sandboxphala-cloud/templates/bytebot

Note: These templates use pre-built Docker images. For full auditability, review their source repos before deployment.

See the full Phala Cloud templates for more options.


Details

Implementation details and infrastructure patterns.

ExampleDescription
launcherGeneric launcher pattern for Docker Compose apps
prelaunch-scriptPre-launch script patterns (Phala Cloud)
private-docker-image-deploymentUsing private Docker registries
attestation/rtmr3-basedRTMR3-based attestation (legacy)

Documentation

Development

./dev.sh help              # Show available commands
./dev.sh validate <example> # Validate a specific example
./dev.sh validate-all      # Validate all examples

Community

License

Apache 2.0 — see LICENSE.


⬆ Back to top