AGENT SKILL

ramdisk-tmpfs-patterns

暂无简介

License 许可
Apache-2.0
最近更新
2026-11-11
Stars
★ 13
Forks
1

03 SKILL.md 正文

/ramdisk-tmpfs-patterns

When to Use

  • Sandbox needs a fast scratch area that auto-destructs when session ends
  • Multiple agents writing temporary files simultaneously (avoid disk I/O bottleneck)
  • Creating ephemeral workspace for untrusted code execution
  • Log staging before flush to persistent append-only store

Do NOT use for

  • Storing data that must survive process restart
  • Large data (> available RAM) — falls back to swap, defeating the purpose

Linux tmpfs mount (bash)

create_ramdisk() {
  local mount_point="$1"
  local size="${2:-64m}"   # default 64MB

  mkdir -p "$mount_point"
  mount -t tmpfs -o "size=${size},mode=1777,nosuid,nodev,noexec" \
    tmpfs "$mount_point"

  echo "[ramdisk] mounted ${size} at ${mount_point}"
  trap "umount -l '$mount_point' && rm -rf '$mount_point'" EXIT
}

# Usage
create_ramdisk /tmp/agent-scratch 128m
# → writes here never touch disk, auto-unmounted on script exit

Per-session ramdisk (no root via user namespace + tmpfs)

# Rootless: bwrap already puts a tmpfs at /tmp — just use it
# Or bind a tmpfs into an existing user namespace:
unshare --mount bash -c "
  mount -t tmpfs -o size=64m,nosuid,nodev tmpfs /tmp/agent-\$\$
  export AGENT_TMP=/tmp/agent-\$\$
  exec '$@'
"

Node.js ramdisk (mafintosh/ramdisk pattern)

import { execSync } from 'child_process'
import { mkdtempSync, rmdirSync, rmSync, existsSync } from 'fs'
import { tmpdir }   from 'os'
import { join }     from 'path'

/**
 * Creates a tmpfs-backed directory (Linux only).
 * Falls back to OS tmpdir on other platforms.
 */
export function createRamdisk(sizeMb = 64): { path: string; cleanup: () => void } {
  const base   = join(tmpdir(), 'ramdisk-')
  const dir    = mkdtempSync(base)

  if (process.platform === 'linux') {
    execSync(`mount -t tmpfs -o size=${sizeMb}m,nosuid,nodev,mode=700 tmpfs "${dir}"`)
  }

  const cleanup = () => {
    if (process.platform === 'linux') {
      try { execSync(`umount -l "${dir}"`) } catch { /* already unmounted */ }
    }
    try { rmSync(dir, { recursive: true, force: true }) } catch { /* already removed */ }
  }

  process.on('exit',    cleanup)
  process.on('SIGTERM', cleanup)
  process.on('SIGINT',  cleanup)

  return { path: dir, cleanup }
}

Race-condition-free temp directory

# Use mktemp -d for unique per-agent directories
AGENT_TMP="$(mktemp -d /tmp/agent-XXXXXXXX)"
trap 'rm -rf "$AGENT_TMP"' EXIT

# Verify it's on tmpfs (optional — still safe if not)
df -T "$AGENT_TMP" | grep -q tmpfs && echo "[ramdisk] on tmpfs" || echo "[ramdisk] on disk"

Size enforcement

# Periodically check usage and abort if over 80%
check_ramdisk_usage() {
  local mount="$1"
  local used_pct; used_pct=$(df "$mount" | awk 'NR==2{print $5}' | tr -d '%')
  if [[ "$used_pct" -gt 80 ]]; then
    echo "[ramdisk] WARNING: ${used_pct}% used at ${mount}" >&2
    return 1
  fi
}

Anti-Fake-Pass Checklist

❌ tmpfs without size limit → sandbox fills all available RAM
❌ nosuid/nodev/noexec not set → sandbox can run SUID binaries from tmpfs
❌ No cleanup trap → tmpfs mounts accumulate across sessions
❌ mktemp not used for unique dirs → concurrent agents collide on same path
❌ Ramdisk created as root on multi-user system → other users can read scratch
❌ mode not set → tmpfs world-writable, any process can read agent scratch
❌ swap not disabled → tmpfs data can land on swap → defeats ephemeral goal

04 同仓库更多 Skills

Horonomos-laps
Horonomos-laps/Yana-AI

openai--sentry--sentry

Use when the user asks to inspect Sentry issues or events, summarize recent production errors, or pull basic Sentry health data via the Sentry API; perform read-only queries with the bundled script and require `SENTRY_AUTH_TOKEN`.

★ 13
Horonomos-laps
Horonomos-laps/Yana-AI

ito-basket-compare

Compare Itô prediction-market baskets against a user's knowledge base, portfolio notes, financial context, watchlist, or research thesis. Use for read-only basket comparison and gap analysis without investment advice or live trading.

★ 13
Horonomos-laps
Horonomos-laps/Yana-AI

implementing-network-traffic-baselining

Build network traffic baselines from NetFlow/IPFIX data using Python pandas for statistical analysis, z-score anomaly detection, and hourly/daily traffic pattern profiling

★ 13
Horonomos-laps
Horonomos-laps/Yana-AI

detecting-evasion-techniques-in-endpoint-logs

Detects defense evasion techniques used by adversaries in endpoint logs including log tampering, timestomping, process injection, and security tool disabling. Use when investigating suspicious endpoint behavior, building detection rules for evasion tactics, or conducting threat hunting for stealthy adversary activity. Activates for requests involving evasion detection, defense evasion analysis, log tampering detection, or MITRE ATT&CK TA0005.

★ 13
Horonomos-laps
Horonomos-laps/Yana-AI

implementing-microsegmentation-with-guardicore

Implementing microsegmentation using Akamai Guardicore Segmentation to map application dependencies, create granular network policies, visualize east-west traffic flows, and enforce least-privilege communication between workloads across data centers and cloud.

★ 13
Horonomos-laps
Horonomos-laps/Yana-AI

ramdisk-tmpfs-patterns

暂无简介

★ 13