<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-to-let-an-ai-agent-run-and-verify-its-own-code-safely-gsgckl4ag" -->

---
title: How to let an AI agent run and verify its own code safely
description: Running AI-generated backend code safely requires more than a sandbox. The post describes a verification loop that combines typed contracts (catching shape...
canonical: https://daily.dev/posts/how-to-let-an-ai-agent-run-and-verify-its-own-code-safely-gsgckl4ag
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How to let an AI agent run and verify its own code safely | daily.dev
og:description: Running AI-generated backend code safely requires more than a sandbox. The post describes a verification loop that combines typed contracts (catching shape...
og:url: https://daily.dev/posts/how-to-let-an-ai-agent-run-and-verify-its-own-code-safely-gsgckl4ag
og:image: https://api.daily.dev/og/posts/gSgCkl4ag.png
og:image:alt: How to let an AI agent run and verify its own code safely
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How to let an AI agent run and verify its own code safely

**[Encore](https://daily.dev/sources/encore-blog)** · 7 min read · 0 upvotes · 0 comments

## Summary

Running AI-generated backend code safely requires more than a sandbox. The post describes a verification loop that combines typed contracts (catching shape errors at compile time), real infrastructure (Postgres via Docker instead of mocks), per-PR preview environments with realistic data, and an MCP server that lets the agent inspect live schema, call its own endpoints, and read traces. Together these replace the agent's assumptions with observable facts, so code earns its way to production by surviving real checks rather than just passing mocks. Business logic correctness still requires human review, but reviewers see evidence of behavior rather than raw generated code.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://encore.dev/blog/agent-verify-loop>

## Similar posts on daily.dev

- [Agentic development hinges on verification. For cloud-native software, that is a runtime problem.](https://daily.dev/posts/agentic-development-hinges-on-verification-for-cloud-native-software-that-is-a-runtime-problem--aknq5rc05) · The New Stack · 1 upvotes · 0 comments
- [Code that runs is not code that's correct: 4 ways to trust an AI-written data pipeline](https://daily.dev/posts/code-that-runs-is-not-code-that-s-correct-4-ways-to-trust-an-ai-written-data-pipeline-6o63ugcr5) · MotherDuck · 1 upvotes · 0 comments
- [Fixing AI-generated code: 5 ways to debug, test, and ship safely](https://daily.dev/posts/fixing-ai-generated-code-5-ways-to-debug-test-and-ship-safely-zqhucjkja) · LogRocket · 1 upvotes · 0 comments

---

Tags: [#typescript](https://daily.dev/tags/typescript), [#ai-agents](https://daily.dev/tags/ai-agents), [#mcp](https://daily.dev/tags/mcp)

[View this post on daily.dev](https://daily.dev/posts/how-to-let-an-ai-agent-run-and-verify-its-own-code-safely-gsgckl4ag)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"How to let an AI agent run and verify its own code safely","url":"https://daily.dev/posts/how-to-let-an-ai-agent-run-and-verify-its-own-code-safely-gsgckl4ag","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-to-let-an-ai-agent-run-and-verify-its-own-code-safely-gsgckl4ag"},"datePublished":"2026-07-21T14:27:34.553Z","dateModified":"2026-07-21T14:29:27.926Z","description":"Running AI-generated backend code safely requires more than a sandbox. The post describes a verification loop that combines typed contracts (catching shape...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/db7bfa782dd1348c0d480a9756b8a94e?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/db7bfa782dd1348c0d480a9756b8a94e?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Encore","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Encore","logo":"https://media.daily.dev/image/upload/s--8Bz0eBFn--/f_auto,q_auto/v1780213589/logos/encore-blog?_a=BAMAMiWQ0","url":"https://daily.dev/sources/encore-blog"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/how-to-let-an-ai-agent-run-and-verify-its-own-code-safely-gsgckl4ag","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"typescript,ai-agents,mcp","timeRequired":"PT7M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Encore","item":"https://daily.dev/sources/encore-blog"},{"@type":"ListItem","position":3,"name":"How to let an AI agent run and verify its own code safely"}]}
```

