Skip to main content

Encrypted compute layer for AI agents

Project description

NXD 0.4.1

NXD is an encrypted compute layer for AI agents. It wraps fully homomorphic encryption, credential vaulting, privacy primitives, and operator-only reveal flows behind a single Python import so developers can run agents on sensitive data without exposing client records, credentials, or proprietary code to models, clouds, or MCP servers.

Three guarantees

  1. The agent works fully - capability unchanged; scores, matches, charges, and aggregates complete normally.
  2. The agent sees nothing - when shield() is used for full payload encryption. vault.safe_use() prevents credential leakage from callbacks. redact() reduces PII exposure but is not a guarantee wall.
  3. The operator holds the keys - keys stay local, auditable, and revocable.

Install

export NXD_OPERATOR_PASSPHRASE="NXD-2026-Nexplora-Secure!"
pip install nxd==0.4.1

Requires Python 3.10 or 3.11 for the FHE path (concrete-ml).

Passphrase Requirements

NXD_OPERATOR_PASSPHRASE must be:

  • At least 12 characters
  • A mix of letters, numbers, and symbols
  • Not a common word or phrase

Strong example: NXD-2026-Nexplora-Secure!

Weak examples rejected at startup: nexplora2026, password123

Your vault security depends entirely on passphrase strength. A weak passphrase is vulnerable to offline dictionary attacks if the vault files are obtained.

Quick start

import nxd

# 1. Shield code before any AI call
code = "api_key = 'sk_live_xxxx'"
shielded = nxd.shield(code)
recovered = nxd.unshield(shielded)
print(f"AI sees:  {shielded[:40]}...")
print(f"You see:  {recovered}")
print(f"Match:    {code == recovered}")

# 2. Redact PII before sending to AI
note = "Patient John Smith, DOB 1985-04-12, SSN 432-11-5678"
clean, mapping = nxd.redact(note)
print(f"\nAI gets:  {clean}")
print(f"Original: {nxd.deredact(clean, mapping)}")

# 3. Vault a credential and use it without returning it
vault = nxd.Vault(agent_id="my-agent")
vault.store("stripe_key", "sk_live_xxxx")
result = vault.safe_use(
    "stripe_key",
    lambda key: {"status": "charged", "auth_len": len(key)},
)
print(f"\nAgent got: {result}")
print("Key seen:  never")

# 4. Verify tamper-proof audit chain
nxd.audit.log("session", agent_id="my-agent")
print(f"\nAudit valid: {nxd.audit.verify()}")

Redaction Levels

redact() returns both the safe text and the local restoration mapping:

import nxd

safe, mapping = nxd.redact("Patient John Smith, SSN 432-11-5678")
restored = nxd.deredact(safe, mapping)
print(safe)
print(restored)

redact() catches common PII and secret formats including emails, phone numbers, SSNs, many API key families, bearer tokens, JWTs, physician names, dates, connection strings, and account numbers.

Important: redact() is pattern-based detection. It reduces exposure, but it is not a guaranteed wall. For complete payload protection, combine it with shield().

redact_strict() is the guaranteed path for opaque transport. It pattern-redacts first, then shields the remaining payload so no plaintext survives in the returned value.

import nxd

shielded, recovery = nxd.redact_strict(
    "John Smith SSN 432-11-5678 sk_live_real_key_here UNUSUAL_FORMAT_12345"
)
restored = nxd.deredact_strict(shielded, recovery)
print("sk_live" not in shielded)
print(restored)

Security Model

Memory Safety

NXD provides SecureString for credential handling that zeroes memory on deletion.

import os
import nxd

vault = nxd.Vault(agent_id="memory-safe")

# Strongest pattern — load from environment and remove immediately
os.environ["API_KEY"] = "sk_live_env_secret_value_2026"
with nxd.SecureString.from_env("API_KEY") as s:
    vault.store("api_key", s.read())

# SecureString — zeroes memory on context exit
with nxd.SecureString("sk_live_example_secret_value_2026") as s:
    vault.store("api_key_copy", s.read())

# secure_store() — zeroes after storing
my_secret = bytearray(b"sk_live_buffered_secret")
vault.secure_store("buffered_key", my_secret)
print(vault.use("api_key_copy", lambda value: len(value)))

Honest caveat: Python string interning means zero-on-delete is still best-effort for short values. SecureString.from_env() is the strongest local pattern because the environment variable is removed immediately after loading.

Callback Safety

Use safe_use() in production to detect accidental credential leakage in callback return values.

import nxd

vault = nxd.Vault(agent_id="callback-safe")
vault.store("stripe_key", "sk_live_xxxx")

class stripe:
    @staticmethod
    def charge(key, amount):
        return {"status": "charged", "amount": amount, "auth_len": len(key)}

# safe_use() raises CredentialLeakError if callback returns credential data
result = vault.safe_use("stripe_key", lambda k: stripe.charge(k, amount=100))
print(result)

# use() when you need callback flexibility
# but callbacks must USE credentials, not RETURN them

Audit Integrity

Audit chain is protected against:

  • Entry modification via HMAC-signed entries
  • Entry injection via sequential hash verification
  • Entry reordering via chained previous-hash checks
  • Entry truncation via a signed manifest with entry count and tail hash

If the manifest is lost, recover with:

import nxd

nxd.audit.log("example", agent_id="recover-demo")
print(nxd.audit.verify())
print(nxd.audit.recover())
print(nxd.audit.verify())

CLI equivalent:

nxd audit-recover

Back up ~/.nxd/ regularly. Losing master.key means losing access to all vaulted data.

Hosted Key Management

For deployments where local key custody is not acceptable, use the hosted backend:

export VAULT_ADDR="http://127.0.0.1:8200"
export VAULT_TOKEN="replace-me"
python3 -c "import nxd; print(type(nxd.Vault(agent_id='prod-agent', hosted=True)).__name__)"

Hosted mode keeps credentials out of ~/.nxd/ and delegates secret custody to HashiCorp Vault.

Import Surface

import nxd

vault = nxd.Vault(agent_id="imports")

# Memory-safe credential handling
with nxd.SecureString("sk_live_example_secret_value_2026") as s:
    vault.store("key", s.read())

credential = bytearray(b"sk_live_buffer")
vault.secure_store("key", credential)    # zeroes after store
vault.safe_use("key", lambda callback_cred: {"status": "ok", "len": len(callback_cred)})  # detects callback leaks
print(nxd.CredentialLeakError.__name__)  # raised on leak detection
print(nxd.PrivacyBudgetExceededError.__name__)
shielded, recovery = nxd.redact_strict("John Smith SSN 432-11-5678")
print(nxd.deredact_strict(shielded, recovery))
import os
os.environ["IMPORT_SURFACE_SECRET"] = "import_surface_secret_value_2026"
with nxd.SecureString.from_env("IMPORT_SURFACE_SECRET") as env_secret:
    print(env_secret.read())

# Audit recovery
print(nxd.audit.recover())               # rebuild manifest
# CLI: nxd audit-recover

Handoff tokens

Handoff tokens are single-use. A token that has already been unpacked raises ReplayError if it is unpacked again.

import nxd

handoff = nxd.Handoff()
token = handoff.pack({"client": "Jane Doe", "balance": 50000})
payload = handoff.unpack(token)
print(payload)

For multi-agent workflows where the same context is needed by multiple agents, pack a separate token for each agent.

Audit export

import nxd

nxd.audit.log("docs-example", agent_id="my-agent")
nxd.audit.export("audit_report.json")
print("export works")

Benchmarks (MacBook Air, Python 3.11, Concrete ML 1.9.0)

Operation Latency Notes
FHE score (1 record) ~183 ms First-call cold start
FHE score (1k records, parallel) 1.6 s 8 cores, ~1.6 ms/record
FHE match (single pair) 352 ms Cross-system comparison
FHE aggregate (1k records, parallel) 1.8 s ~0.009% quantization error
Credential vault use <1 ms Decrypt in memory only
Proof suite 114/114 passed python3 prove.py
Real-world simulation 34/34 passed python3 realworld.py
Pytest suite 72 passed pytest -q

What NXD does not protect against

NXD protects credentials and sensitive data from AI providers, model context, and ordinary cloud exposure. It does not remove the need for normal endpoint security and key management discipline.

  • Local deployments still inherit host risk. Vault(hosted=True) removes local key custody, but Vault(hosted=False) still stores encrypted key material on the operator machine.
  • split() and blur() are still pending external cryptographic review. They now ship with import-time self-tests, split self-verification, and privacy-budget guards, but that is not a substitute for independent review.
  • redact() remains best-effort pattern detection. Use redact_strict() when you need guaranteed opaque output.
  • SecureString, secure_store(), and SecureString.from_env() are stronger patterns than raw strings, but CPython memory behavior means zeroing remains best-effort for short secrets.
  • NXD uses FHE for specific compute operations such as score, match, and aggregate. It does not run the full LLM context window under FHE.
  • NXD does not protect against a trusted operator with physical access, because that operator holds the keys by design.
  • Current encryption choices are not presented as quantum-resistant. Post-quantum primitives are not part of the current release.

Operator workflow

Set NXD_OPERATOR_PASSPHRASE before using the vault, audit chain, signatures, or any operator-only reveal flow. NXD stores ciphertext at rest, and local key files are wrapped with a PBKDF2-derived key from that operator passphrase.

When you use nxd init, NXD can vault .env secrets, replace them with NXD_VAULT::NAME references, and write an encrypted .env.backup.nxd recovery file.

On the MCP path, decrypt-style tools such as nxd_unshield, nxd_unseal_text, and nxd_detokenize no longer return plaintext to the agent. They queue an operator-only reveal:

nxd reveal <reveal_id>

Roadmap

v0.3.x (shipped)

  • ✅ Agent vault isolation
  • ✅ Concurrent vault safety
  • ✅ Passphrase strength enforcement
  • ✅ API key redaction coverage
  • ✅ Audit truncation detection
  • ✅ Uniform error messages (VaultError)
  • SecureString memory safety
  • safe_use() leak detection
  • ✅ Audit manifest recovery
  • ✅ HashiCorp Vault hosted mode
  • redact_strict() guaranteed opaque transport
  • SecureString.from_env() and SecurityWarning
  • split() self-tests and runtime self-verification
  • blur() privacy-budget enforcement and import self-test

v0.4.0 (shipped)

  • Managed backend expansion (AWS KMS, Vault transit patterns, stronger auth flows)
  • Production hosted deployment ergonomics

v0.5.0 (next)

  • External cryptographic audit of split() and blur()
  • Formal security certification

v0.6.0

  • Hardware-accelerated FHE on GPU/TPU
  • Sub-10 ms encrypted inference

Development

git clone https://github.com/Nexploraai/nxd
cd nxd
pip install -e ".[dev]"
python3 prove.py
pytest -q
python3 realworld.py

License

Proprietary - Nexplora Labs. Free to use in projects, but the source may not be modified, redistributed, resold, or used to build a competing encryption or agent-protection product. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nxd-0.4.1.tar.gz (56.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nxd-0.4.1-py3-none-any.whl (45.2 kB view details)

Uploaded Python 3

File details

Details for the file nxd-0.4.1.tar.gz.

File metadata

  • Download URL: nxd-0.4.1.tar.gz
  • Upload date:
  • Size: 56.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for nxd-0.4.1.tar.gz
Algorithm Hash digest
SHA256 a0c0dd75303c19077b5f04b9c85bf0c38af3bba2bd7aa1f2d7c6b25bd774f39c
MD5 4bc78885e2a197327cc57716c64c5145
BLAKE2b-256 937c039da36b1caab2656968bb332e6a66ace979c8151df4558414ac367cad68

See more details on using hashes here.

File details

Details for the file nxd-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: nxd-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 45.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for nxd-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 38786b3fadeb5acf4a10b447aa191c3c1354fa51e0fe29d36b5f147ce9ceb543
MD5 2038918473788e906e08751809a8f486
BLAKE2b-256 51fed4659fea635710edf6edeccb6454f1203485621b0edd6597b512eb9b62b6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page