Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions examples/e2b-daytona-template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# AgentShield + DBShield Inside E2B / Daytona Cloud Sandboxes

Official production template for running autonomous AI coding agents inside **E2B microVMs** or **Daytona DevContainers** with zero-leak credential redaction (**AgentShield**), PostgreSQL wire-protocol SQL guardrails (**DBShield**), and air-gapped defaults (`RITUAL_AIR_GAPPED=1`).

## Files

- `e2b.Dockerfile` — Non-root (`UID 10001`) hardened container image bundling `@ritualdev-lab/agentshield>=0.2.2`, `@ritualdev-lab/dbshield>=0.2.1`, and `bubblewrap`.
- `daytona-devcontainer.json` — DevContainer / Daytona workspace manifest enforcing `--cap-drop=ALL`, `--security-opt=no-new-privileges:true`, `--read-only` rootfs, and the canonical `ritualdev-lab.agentshield-defense` IDE extension.
- `entrypoint.sh` — Runs `agentshield doctor` preflight and supports `--exec-guarded <command>` wrapped command execution.

## E2B MicroVM Quickstart

```bash
cd examples/e2b-daytona-template
e2b template build --name ritual-agentshield-sandbox --dockerfile e2b.Dockerfile
```

## Daytona Workspace Quickstart

```bash
daytona create https://github.com/RitualDev-Lab/AgentShield \
--devcontainer-path examples/e2b-daytona-template/daytona-devcontainer.json
```

## Unified 3-Layer Policy Boot

Inside the microVM or Daytona workspace, validate or boot the full stack via `ritual.policy.yaml`:

```bash
agentshield up --config ../ritual.policy.yaml --dry-run
```
41 changes: 41 additions & 0 deletions examples/e2b-daytona-template/daytona-devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "AgentShield + DBShield Secure Cloud Sandbox (Daytona / DevContainer)",
"build": {
"dockerfile": "e2b.Dockerfile",
"context": "."
},
"remoteUser": "agent",
"containerEnv": {
"RITUAL_AIR_GAPPED": "1",
"AGENTSHIELD_AIR_GAPPED": "1",
"AGENTSHIELD_MODE": "strict",
"DBSHIELD_SAFETY_TIER": "STRICT"
},
"runArgs": [
"--cap-drop=ALL",
"--security-opt=no-new-privileges:true",
"--read-only",
"--tmpfs=/tmp:rw,noexec,nosuid,size=256m"
],
"forwardPorts": [5433, 4310],
"portsAttributes": {
"5433": {
"label": "DBShield PostgreSQL Wire Proxy",
"onAutoForward": "silent"
},
"4310": {
"label": "SkillPrism MCP Context Compactor",
"onAutoForward": "silent"
}
},
"postCreateCommand": "agentshield doctor --json > /tmp/agentshield-doctor.json || true",
"customizations": {
"vscode": {
"extensions": ["ritualdev-lab.agentshield-defense"],
"settings": {
"agentshield.airGappedMode": true,
"agentshield.strictLeakBlocking": true
}
}
}
}
42 changes: 42 additions & 0 deletions examples/e2b-daytona-template/e2b.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Official RitualDev-Lab E2B / Daytona MicroVM Sandbox Template
# Bundles AgentShield (>=0.2.2) + DBShield (>=0.2.1) in a non-root air-gapped workspace.
FROM node:22-bookworm-slim

LABEL org.opencontainers.image.title="AgentShield + DBShield E2B/Daytona Sandbox" \
org.opencontainers.image.description="Hardened non-root cloud sandbox microVM with AgentShield zero-leak redaction and DBShield SQL wire firewall" \
org.opencontainers.image.source="https://github.com/RitualDev-Lab/AgentShield" \
org.opencontainers.image.licenses="Apache-2.0"

# Install minimal runtime utilities and bubblewrap for nested kernel confinement
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
curl \
git \
bubblewrap \
jq \
&& rm -rf /var/lib/apt/lists/*

# Install canonical RitualDev-Lab defense CLIs globally (pinned minimum versions)
RUN npm install -g \
@ritualdev-lab/agentshield@>=0.2.2 \
@ritualdev-lab/dbshield@>=0.2.1 \
&& npm cache clean --force

# Create unprivileged agent user (UID 10001)
RUN groupadd -g 10001 agent && useradd -m -u 10001 -g 10001 -s /bin/bash agent

WORKDIR /workspace
COPY --chown=10001:10001 entrypoint.sh /usr/local/bin/ritual-entrypoint.sh
RUN chmod 0755 /usr/local/bin/ritual-entrypoint.sh

# Enforce strict offline air-gapped defaults
ENV RITUAL_AIR_GAPPED=1 \
AGENTSHIELD_AIR_GAPPED=1 \
AGENTSHIELD_MODE=strict \
DBSHIELD_SAFETY_TIER=STRICT \
NODE_ENV=production

USER 10001:10001

ENTRYPOINT ["/usr/local/bin/ritual-entrypoint.sh"]
CMD ["bash"]
23 changes: 23 additions & 0 deletions examples/e2b-daytona-template/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -euo pipefail

# Official RitualDev-Lab E2B / Daytona Cloud Sandbox Entrypoint
# 1. Enforces strict air-gapped environment defaults
# 2. Runs AgentShield sandbox doctor preflight
# 3. Routes executed agent commands through AgentShield zero-leak stream redactor

export RITUAL_AIR_GAPPED="${RITUAL_AIR_GAPPED:-1}"
export AGENTSHIELD_AIR_GAPPED="${AGENTSHIELD_AIR_GAPPED:-1}"
export AGENTSHIELD_MODE="${AGENTSHIELD_MODE:-strict}"
export DBSHIELD_SAFETY_TIER="${DBSHIELD_SAFETY_TIER:-STRICT}"

if command -v agentshield >/dev/null 2>&1; then
agentshield doctor --json >/tmp/agentshield-preflight.json 2>&1 || true
fi

if [ "$#" -gt 0 ] && [ "$1" = "--exec-guarded" ]; then
shift
exec agentshield exec "$*"
fi

exec "$@"
64 changes: 64 additions & 0 deletions tests/phase10-e2b-daytona-template.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import assert from "node:assert/strict";
import { existsSync, readFileSync } from "node:fs";
import { resolve } from "node:path";
import test from "node:test";
import { AgentShieldEngine } from "../src/engine.js";
import { AgentCommandSandbox } from "../src/sandbox.js";

const TEMPLATE_DIR = resolve("examples/e2b-daytona-template");

test("Phase 10: E2B / Daytona cloud sandbox template ships hardened Dockerfile, DevContainer, and entrypoint", () => {
const dockerfilePath = resolve(TEMPLATE_DIR, "e2b.Dockerfile");
const devcontainerPath = resolve(TEMPLATE_DIR, "daytona-devcontainer.json");
const entrypointPath = resolve(TEMPLATE_DIR, "entrypoint.sh");
const readmePath = resolve(TEMPLATE_DIR, "README.md");

assert.ok(existsSync(dockerfilePath), "e2b.Dockerfile must exist");
assert.ok(existsSync(devcontainerPath), "daytona-devcontainer.json must exist");
assert.ok(existsSync(entrypointPath), "entrypoint.sh must exist");
assert.ok(existsSync(readmePath), "README.md must exist");

const dockerfile = readFileSync(dockerfilePath, "utf8");
assert.match(dockerfile, /@ritualdev-lab\/agentshield@>=0\.2\.2/);
assert.match(dockerfile, /@ritualdev-lab\/dbshield@>=0\.2\.1/);
assert.match(dockerfile, /USER 10001:10001/);
assert.match(dockerfile, /RITUAL_AIR_GAPPED=1/);
assert.match(dockerfile, /DBSHIELD_SAFETY_TIER=STRICT/);
assert.match(dockerfile, /ENTRYPOINT \["\/usr\/local\/bin\/ritual-entrypoint\.sh"\]/);

const devcontainer = JSON.parse(readFileSync(devcontainerPath, "utf8"));
assert.equal(devcontainer.remoteUser, "agent");
assert.equal(devcontainer.containerEnv.RITUAL_AIR_GAPPED, "1");
assert.equal(devcontainer.containerEnv.DBSHIELD_SAFETY_TIER, "STRICT");
assert.ok(devcontainer.runArgs.includes("--cap-drop=ALL"));
assert.ok(devcontainer.runArgs.includes("--security-opt=no-new-privileges:true"));
assert.ok(devcontainer.runArgs.includes("--read-only"));
assert.ok(devcontainer.forwardPorts.includes(5433));
assert.ok(
devcontainer.customizations.vscode.extensions.includes("ritualdev-lab.agentshield-defense"),
);

const entrypoint = readFileSync(entrypointPath, "utf8");
assert.match(entrypoint, /set -euo pipefail/);
assert.match(entrypoint, /agentshield doctor --json/);
assert.match(entrypoint, /agentshield exec/);
});

test("Phase 10: step-by-step microVM tool & credential interception enforces zero-leak guarantees", () => {
const sandbox = new AgentCommandSandbox();
const engine = new AgentShieldEngine();

// Step 1: Benign workspace command permitted inside microVM
const safeCheck = sandbox.inspectCommand("git status --short");
assert.equal(safeCheck.isBlocked, false);

// Step 2: Adversarial credential dump command blocked before execution
const envDump = sandbox.inspectCommand("cat /proc/self/environ && cat .env");
assert.equal(envDump.isBlocked, true);

// Step 3: Tool output carrying synthetic runtime credential is redacted cleanly
const syntheticPat = ["ghp", "a".repeat(36)].join("_");
const redacted = engine.scanAndRedact(`psql output: token=${syntheticPat}`);
assert.ok(redacted.findings.length >= 1);
assert.equal(redacted.sanitizedText.includes(syntheticPat), false);
});
Loading