Zero‑exposure cross‑device script authorization using MGC Blackbox. Scripts are sealed with the target node's RSA public key, delivered as ciphertext, and decrypted only in memory on the authorized node; also supports key‑exchange‑free free mode for public distribution. Adapted to MGC 1.5.4 — dual‑l
Cross‑Device Encrypted Script Authorization is a documentation skill that teaches how to authorize script execution across devices without exposing plaintext.
This skill enables:
Seal scripts using the target node's RSA public key and deliver them as ciphertext
Also support a key‑exchange‑free free mode for public distribution
Run sealed scripts on the authorized node via blackbox execution
Verify the origin of an artifact through link authorization
This skill contains no executable code and is safe for automatic approval.
What This Skill Enables
After reading this documentation, the caller will understand how to:
Fetch the target node's RSA public key (__NODE_PUB__)
Seal scripts via mgc_seal (with auto-extracted default arguments), producing a deliverable capsule file
Choose the authorization mode: p2p (bound to a specific node) or free mode (runnable on any 1.5.4+ node)
Import the capsule on the target node with a single call (all fields parsed automatically)
Execute the sealed script in blackbox mode via mgc_run
Verify artifact origin integrity (tamper detection on ext07 / ext09)
Version requirement: the receiver must run MGC 1.5.4+. Earlier versions cannot unseal artifacts carrying link authorization.
Sandbox mode (1.4.9+): When running inside a sandbox Agent (Trae Work / Workbuddy), install MGC in the system environment; otherwise MCP tool calls may be intercepted — in that case, call FastAPI directly.
The layer-3 key is derived from ext07 (owner node public key) and the AAD binds ext09 (seal mode) — this is exactly where link authorization comes from.
The layer-1 AES_KEY_4 is freshly randomized on every seal and never reused across artifacts.
Public distribution, skill marketplaces, generic installers
Free mode wraps the content with MGC's shared default public key, so any machine running MGC 1.5.4+ can import and run it, while the source script still never lands on disk in plaintext at the receiving side.
Free mode fits "hand everyone a runnable trial build". It is not suitable when authorization must be limited per customer.
Sealed Capsule Structure (measured on 1.5.4)
text
{
"info_type": "script",
"info_owner": "my_script",
"ext01": "python", // startup command
"ext02": '["--name", "World"]', // default args (argparse auto-parsed at seal time)
"ext03": "<dual-layer wrapped ciphertext>", // sealing key
"ext05": "[]", // third-party dependency list (auto-detected)
"ext06": '["windows","macos","linux"]',// compatible platform list (statically inferred)
"ext07": "<owner node RSA public key>", // origin identity, participates in key derivation
"ext09": "p2p mode", // seal mode
"content": "<AES-encrypted script body>"
}
Key points:
Field keys carry no underscore (ext01, not ext_01)
ext07 and ext09must travel with the artifact; if either is missing, it can never be unsealed
ext05 / ext06 are pre-run hints — MGC does not install dependencies for you
Use Cases
Use Case 1: Cross‑Organization Script Sharing
Organization A wants to share scripts with Organization B without exposing script content.
Organization B installs MGC and provides its node_pub
Organization A seals the script with node_pub (p2p mode)
Organization B imports the capsule and executes it
Use Case 2: Trusted Partner Automation
A company wants to deliver automation scripts to partners without revealing the script logic.
Partner installs MGC and provides node_pub
Company seals the script with the partner's node_pub
Partner runs the sealed script locally in blackbox mode
Use Case 3: Delegated Task Execution
A central server delegates tasks to edge devices without exposing task logic.
Edge device provides node_pub to the central server
Central server seals the task script
Edge device executes the sealed task
Use Case 4: Public Distribution (Free Mode)
When the script must reach an unknown audience, or be published on a skill marketplace:
The owner node seals without ext04
The artifact can be placed on a public channel
Any node running MGC 1.5.4+ can import and run it; the source script never lands on disk
Workflow
Step 1: Get Target Node Public Key
Only needed for p2p mode. Free mode can skip this step.
The target node (the node that runs the sealed script) must provide its RSA public key.
Option A: Trigger lazy generation via MCP/API
python
# Fetch node public key via MCP (auto-generates keypair on first call)
node_pub = mgc_get(
info_type="__NODE_PUB__",
info_owner="__NODE_PUB__"
)
Option B: View via WebUI (1.4.7+)
Open WebUI → skill page → Settings dropdown → Node Public Key → Copy multi-line PEM.
On Safari the browser will download a .pem file instead.
Critical requirement: node_pubmust be a multi-line PEM with real newlines:
text
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...
...(base64 lines)...
-----END PUBLIC KEY-----
Single-line concatenation triggers MGC's "Invalid PEM format" error; copy verbatim from the mgc_get response.
Step 2: Seal Script on Owner Node
Store the original script first, then seal it. Sealing produces a self-describing capsule file.
python
# 1. Store the original script first (ext01 required; ext02 optional — MGC auto-parses argparse)
mgc_save(
info_type="script",
info_owner="my_script",
ext01="python",
content="import argparse\nparser = argparse.ArgumentParser()\nparser.add_argument('--name', default='World')\nargs = parser.parse_args()\nprint(f'Hello {args.name}')"
)
# 2. Seal
sealed = mgc_seal(
info_owner="my_script", # required: script identifier to seal
output_dir="/abs/path/to/out", # required: since 1.5.4 there is no desktop fallback, an absolute path must be given
# p2p mode: pass the target node public key; free mode: drop this line entirely
ext04=node_pub
)
# sealed contains:
# capsule_path absolute path of the capsule file
# content / ext01..ext09 the complete self-describing artifact
output_dir is required since 1.5.4 — there is no default location. The artifact lands in
<output_dir>/<info_owner>_<YYYYMMDD_HHMMSS>/sealed_capsule.json.
Free mode: delete the whole ext04 line; all other parameters stay the same.
The parameter name must be ext04: writing node_pub / target_pub / public_key and other aliases
fails immediately with UNKNOWN_PARAM, so you never mistake a free-mode artifact for a node-bound one.
Step 3: Transfer the Sealed Artifact
Hand the whole sealed_capsule.json file pointed to by capsule_path to the receiver — any channel (email / USB / IM) works.
python
import shutil
shutil.copy(sealed["capsule_path"], "/path/to/send/sealed_capsule.json")
# Or paste the JSON file content to the receiver directly
The artifact is ciphertext, but its integrity is guaranteed by link authorization (see the "Link Authorization" chapter). A trusted channel is still recommended.
When forwarding, ext07 / ext09 must be passed through verbatim; any edit makes it unrestorable.
Step 4: Import the Artifact on the Authorized Node
A single call is enough — MGC recognizes the capsule and parses out every field:
python
# On the authorized node (recommended: path import, fewest parameters, type inferred automatically)
mgc_save_file(
path="/path/to/send/sealed_capsule.json",
info_owner="partner_script" # use your own owner, so you don't overwrite the source record on the owner node
)
You can also pass the JSON directly:
python
mgc_save(
info_type="script", # required by this tool's schema, even though the capsule repeats it
info_owner="partner_script",
content=capsule_json_string # the whole capsule JSON, verbatim
)
Never hand-copy fields one by one (ext01 / ext02 / content / ext03) — that drops ext07 and ext09,
and the artifact can then be stored but will never unseal.
Choosing the owner: the info_owner inside the capsule belongs to the owner node. Storing it under the same owner on the same node overwrites the source record; on a different node the owner node is unaffected. Supplying your own owner keeps both copies.
Step 5: Execute the Sealed Script (Blackbox)
python
# ✅ 1.5.4 recommended: use mgc_run
result = mgc_run(
info_type="script",
info_owner="partner_script",
diff_3="partner_script", # most reliable locator: the script's relative path / file name
ext02='["--name", "Alice"]' # optional: runtime override of default args (JSON array string)
)
# Returns e.g.: {"status": "started"}
# The caller only gets the start status; script content is never exposed
diff_1 is no longer required since 1.5.4. Prefer diff_3 (most precise), then diff_2 (folder name).
If multiple records match under the same owner, MGC returns AMBIGUOUS_SCRIPT — list the candidates with mgc_find first, then retry.
Execution output: mgc_run returns only the start status, not stdout. For detailed results, the sealed script should write results to a file and print the path on stdout (see the "Dependency Requirements" chapter).
Step 6: (Optional) List / Find Sealed Scripts
python
# Fuzzy search (1.4.10+)
scripts = mgc_find(
info_owner="partner",
match_mode="substring", # substring / prefix / suffix / exact
limit=50
)
# Returns a metadata list — **never includes content plaintext**
Link Authorization
Since 1.5.4 every sealed artifact carries the owner node's identity (ext07) and the seal mode (ext09). Together they form link authorization.
How It Works
At unseal time, MGC validates in this order:
Derive the outer key SHA256(ext07)[:32] from ext07
Use ext09 as the AAD to validate ciphertext integrity
If validation fails → UNSEAL_FAILED
Because key derivation is bound to ext07 and integrity validation is bound to ext09, any modification to either one makes the artifact unrestorable — even a single added space.
Hands‑On Verification Steps
To confirm locally that this mechanism is really in effect, follow these three steps (all on one machine, no second node needed):
python
# 1. Seal and import
sealed = mgc_seal(info_owner="my_script", output_dir="/tmp/probe")
mgc_save_file(path=sealed["capsule_path"], info_owner="probe_copy")
python
# 2. Tamper with ext09 (append a trailing space) and write a new file
# Python side: append a space to ext09 in the capsule JSON, save as tampered.json
python
# 3. Import the tampered file and run it
mgc_save_file(path="/tmp/probe/tampered.json", info_owner="probe_tampered")
mgc_run(info_type="script", info_owner="probe_tampered")
Measured result:
text
Error: UNSEAL_FAILED
→ Hint: Double-layer unseal failed: AES-GCM auth tag mismatch:
source_node_pub (ext07) or mode (ext09) tampered, or wrong key.
The same principle also enforces "a non-target node cannot unseal": decrypting with a mismatched private key reports
Double-layer unseal failed: Incorrect decryption.
Recommendations
The receiver should check that ext07 matches the owner node's public key (verify through a trusted channel)
Pass ext07 / ext09 through verbatim when forwarding — do not edit or reformat them
ext07 is a plaintext identifier in the artifact, not a signature; it detects tampering and binds the unseal key, and does not replace identity verification
Dependency Requirements
When the sealed script runs on the target node, ensure dependencies are consistent:
Dependency
How to Handle
MGC credentials
Target node must store credentials with the same info_type / info_owner; format consistent but content may vary by node
External files
Paths must be consistent; recommended to also store in MGC and pull via MGC API at runtime
Environment variables
Must be set on the target node
Python libraries
Target node must install the same library versions; at seal time MGC writes the dependency list into ext05, but it does not install them
Cross-platform differences
Use pathlib.Path or / separators; avoid platform-specific APIs. The compatible platform list is written into ext06
Important: Dependency mismatch is the most common cause of sealed script failures. Verify info_type/info_owner, environment variables, and file paths match between source and target before sealing.
Security Notes
Zero exposure: the script is encrypted at rest and during transfer, decrypted only in memory on the target node during execution; plaintext never lands on disk
Blackbox execution: sealed scripts run in MGC's sandbox; the caller cannot see script content
The authorization boundary depends on the mode: in p2p mode only the node holding the matching private key can unseal; in free mode any MGC 1.5.4+ node can unseal — choosing free mode means giving up the "restricted recipient" constraint
Execution right ≠ ownership: the receiver of a p2p artifact can only execute it; it cannot re-seal the owner node's artifact for a third party
No root protection: a malicious root can read the decrypted body during execution; ensure the target node is trusted before authorizing
Integrity is now verifiable: 1.5.4 link authorization detects tampering with ext07 / ext09 (see the "Link Authorization" chapter); but this is origin binding, not a guarantee about the script's runtime behavior
Scope of the guarantee: MGC protects content confidentiality. Once unsealed, the script runs with the permissions of the user running it; which commands it invokes, which files it reads or writes, and which network endpoints it reaches are not restricted by MGC. Those behaviors are the script author's responsibility. Verify the owner node's public key through a trusted channel before importing.
MCP Tools Reference
Tool
Purpose
Required Parameters
mgc_save
Store the original script / pass capsule JSON directly
info_type, info_owner, content
mgc_save_file
Import a capsule by path (recommended) / import a folder / import .mgc_file
PEM format requirement: ext04 must be a multi-line PEM with real newlines (\n). If you see "Invalid PEM format", copy the value verbatim from mgc_get(info_type='__NODE_PUB__').