Building with AILesson 29 of 80

Module 3 · Structure, tools and the loop

Letting a model run code without letting it run your machine

In this lesson

  • 9 min read
  • 7 reading sections
  • Knowledge check
  • Lesson 9 of 11 in this chapter

This chapter’s goalDesign a schema and a tool surface a model can actually follow, write an agent loop with a step budget and a validated boundary at every hop, and say for each failure in that loop whether it should be retried, escalated to a human, or must stop the run.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmNot availableNot available
Full audiobookNot availableNot available

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 8Free · no account needed
Lesson steps

Why a code tool is different from every other tool

Every other tool has a fixed surface. order_status can do exactly one thing, and the worst a wrong call achieves is the wrong order id.

A code-execution tool has no surface. run_python(code) accepts arbitrary programs, which means its capability set is whatever the process it runs in can reach: the filesystem, the network, environment variables, other processes, your cloud metadata endpoint. You have not added a tool. You have added a shell.

That is also why it is valuable. Models are poor at arithmetic and excellent at writing the code that does arithmetic. A model asked to compute a weighted median over 4,000 rows will produce a confident wrong number; asked to write the pandas that computes it, it will usually be right, and the answer is verifiable because you can read the code.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Every lesson here is open. Your progress is recorded once you pass the Python, from Zero, for AI exam.

Stuck on something?Ask Sayali, your AI tutor

How to cite: Addaly (2026) ‘Letting a model run code without letting it run your machine’, in Building with AI. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/building-with-ai/running-code-safely (Accessed: 29 November 2026).