Claude Code और Codex के लिए सुरक्षित Agent Harness: permissions, verification और rollback
Claude Code और Codex agents को सुरक्षित चलाने के लिए policy, plan, verification और recovery layers वाला practical harness design.
Powerful agents को safe rails चाहिए
Claude Code या Codex शुरू में prompt writing जैसा लगता है. छोटे बदलावों के लिए यह ठीक है. लेकिन जब agent deployment, SaaS APIs, local files, publishing या email sending करने लगे, तब असली समस्या prompt नहीं होती. असली समस्या होती है उसके चारों ओर बना execution harness.
इस article में Agent Harness का मतलब है वह बाहरी structure जो AI agent को सुरक्षित तरीके से काम कराता है: permissions, execution plan, verification checks, logs और rollback path.
Concept पहले समझना हो तो harness engineering guide देखें. Practical risk patterns के लिए Claude Code security failure cases भी useful है.
User request
|
v
Agent
|
v
[1] Policy layer क्या allow, ask या deny होगा
[2] Plan layer कौन सा step किस order में चलेगा
[3] Verification layer success कैसे prove होगा
[4] Recovery layer failure के बाद वापस कैसे आएंगे
|
v
Files / shell / SaaS APIs / deploy
Claude Code की official documentation settings, permissions, hooks और MCP को अलग-अलग explain करती है. शुरुआत के लिए Claude Code settings, Hooks reference और MCP देखें.
Example: article publishing harness
“एक article publish करो” असल में कई steps का workflow है.
1. पिछले 7 दिनों का analytics पढ़ना
2. high-performing topic cluster के पास नया topic चुनना
3. existing articles से duplicate check करना
4. source article लिखना
5. सभी language versions बनाना
6. frontmatter, slug और internal links validate करना
7. site build करना
8. live URL check करना
9. commit और push करना
अगर यह plan explicit नहीं है, तो agent visible काम पूरा कर सकता है लेकिन translations, build या live check भूल सकता है.
SaaS integration: read, generate और send को अलग रखें
मान लें agent companies research करता है और outreach email draft करता है.
| Operation | Automatic? | Reason |
|---|---|---|
| Public pages read करना | Yes | Low impact |
| Local CSV save करना | Yes | Reviewable |
| Sample page generate करना | Yes | Publish से पहले check कर सकते हैं |
| Email draft करना | Yes | अभी send नहीं हुआ |
| Email send करना | Approval | External irreversible action |
Agent Harness का core यही है: read, draft, publish और send को अलग permissions दें.
Policy layer
एक simple policy file से शुरुआत करें.
{
"allowCommands": [
"npm run build",
"npm run test",
"node scripts/content-trend-report.mjs"
],
"askCommands": [
"git push",
"wrangler pages deploy",
"node scripts/outreach-send-mails.mjs --send"
],
"denyCommands": [
"rm -rf",
"git reset --hard",
"curl * | sh",
"npm publish"
],
"protectedPaths": [
".env",
".env.local",
"claudecode-lab-sheets-f54fc47c68f0.json"
]
}
Claude Code project settings में भी ऐसी boundary बनाई जा सकती है.
{
"$schema": "https://json.schemastore.org/claude-code-settings.json",
"permissions": {
"allow": [
"Bash(npm run build)",
"Bash(npm run test *)",
"Bash(node scripts/content-trend-report.mjs *)"
],
"ask": [
"Bash(git push *)",
"Bash(wrangler pages deploy *)"
],
"deny": [
"Bash(rm -rf *)",
"Bash(git reset --hard *)",
"Read(./.env)",
"Read(./.env.*)",
"Read(./claudecode-lab-sheets-f54fc47c68f0.json)"
]
}
}
“Secrets का ध्यान रखना” लिखना काफी नहीं है. Secret files और dangerous commands को concrete deny rules में डालें.
Verification layer
Success को command से prove करें.
const url = process.argv[2];
const response = await fetch(url, { redirect: "follow" });
if (!response.ok) {
throw new Error(`Page returned ${response.status}: ${url}`);
}
const html = await response.text();
const checks = [
["title", /<title>.+<\/title>/i],
["description", /<meta name="description"/i],
["adsense", /ca-pub-2125588229998303/i],
["analytics", /G-3YR0LE68MJ/i]
];
for (const [name, pattern] of checks) {
if (!pattern.test(html)) throw new Error(`Missing ${name}`);
}
Code-heavy article में Playwright से mobile width पर pre, code और table overflow भी check करें.
Recovery layer
हर run का log रखें, ताकि failure के बाद पता हो कि क्या बदला.
{
"runId": "2026-05-19-article-001",
"topic": "agent harness security",
"changedFiles": [
"site/src/content/blog/claude-code-codex-agent-harness-security.mdx"
],
"commands": [
"node scripts/content-trend-report.mjs --days 7",
"npm run build"
],
"status": "deployed"
}
Git में broad reset की जगह targeted recovery बेहतर है.
git status --short
git diff -- site/src/content/blog/target-article.mdx
git revert <bad-commit>
Summary
AI agent की quality सिर्फ prompt quality नहीं है. Real workflows में quality harness से आती है.
- Policy: क्या allow, ask और deny होगा
- Plan: execution से पहले steps clear करना
- Verification: success को command से prove करना
- Recovery: failure के बाद वापस आने का तरीका रखना
Claude Code और Codex अलग tools हैं, लेकिन दोनों को यही structure चाहिए: unlimited execution नहीं, बल्कि safe path for useful work.
मुफ़्त PDF: 5 मिनट में Claude Code चीटशीट
बस अपना ईमेल दर्ज करें और हम तुरंत A4 एक-पृष्ठ चीटशीट PDF भेज देंगे।
हम आपकी व्यक्तिगत जानकारी की सुरक्षा करते हैं और स्पैम नहीं भेजते।
लेखक के बारे में
Masa
Claude Code का गहराई से उपयोग करने वाले इंजीनियर। claudecode-lab.com चलाते हैं, जो 10 भाषाओं में 2,000 से अधिक पेजों वाला टेक मीडिया है।
संबंधित लेख
Claude Code Subagent के लिए 10 शक्तिशाली पैटर्न
Claude Code की subagent सुविधा में महारत हासिल करें 10 व्यावहारिक पैटर्न के साथ। समानांतर प्रसंस्करण, विशेषज्ञता, संदर्भ अलगाव सीखें।
Claude Code Agent SDK का परिचय — स्वायत्त एजेंट तेज़ी से बनाएं
Claude Code Agent SDK से स्वायत्त AI एजेंट बनाना सीखें। सेटअप, टूल परिभाषा और मल्टी-स्टेप निष्पादन को व्यावहारिक कोड उदाहरणों के साथ समझें।
Claude Code में कॉन्टेक्स्ट प्रबंधन तकनीकों की संपूर्ण गाइड
Claude Code की कॉन्टेक्स्ट विंडो को अधिकतम रूप से उपयोग करने की व्यावहारिक तकनीकें। टोकन अनुकूलन, वार्तालाप विभाजन और CLAUDE.md का उपयोग।