mistralM

Docs

sideBar

Environment

Give the agent a computer to run shell commands, edit files and run Python, and choose what that computer can reach.

The environment is the computer where your agent runs shell commands, edits files and runs Python: a sandbox that you set with the agent's environment=. The SDK creates the sandbox when a session starts and deletes it when the session closes.

Give the agent a sandbox

The example below uses MistralSandbox, a sandbox hosted by Mistral. It needs:

  • The sandbox extra: uv add "mistralai-agents[koyeb]". A project made by agents init has it.
  • MISTRAL_API_KEY: the SDK creates the sandbox with it, so you need no other credential. A Mistral-managed deployment uses its service account instead.
  • The cloud_user workspace role: see Requirements.

Pass a sandbox as the agent's environment=:

import asyncio

from mistralai import agents

agent = agents.Agent(
    model="mistral-large-4",
    instructions="Use bash to answer.",
    environment=agents.MistralSandbox(),
)

async def main() -> None:
    result = await agent.run("Which Python version does the sandbox have?")
    if isinstance(result, agents.Completed):
        print(result.text)
        print([call.name for call in result.tool_calls])

asyncio.run(main())

Output:

The sandbox has **Python 3.12.15**.
['file_system.bash']

The model ran a shell command in a Mistral-managed container.

Built-in sandboxes

from mistralai import agents

agents.Agent(model="mistral-large-4")                                     # NoSandbox (default): no code execution
agents.Agent(model="mistral-large-4", environment=agents.MistralSandbox())      # a Mistral-managed container
agents.Agent(model="mistral-large-4", environment=agents.LocalDockerSandbox())  # a container on your machine
agents.Agent(model="mistral-large-4", environment=agents.BashkitSandbox())      # an in-process Bash interpreter
agents.Agent(model="mistral-large-4", environment=agents.DangerousLocalSandbox())  # your own machine, no isolation

Start with MistralSandbox; use LocalDockerSandbox for tests and CI.

Sandbox

Use it for

Python and background processes

Needs

NoSandboxagents that only call tools and connectorsnonothing
MistralSandboxdeployed agents, and any agent that runs untrusted codeyes; with a custom image, background processes are off by defaultthe sandbox extra and the cloud_user role
LocalDockerSandboxlocal development and CIyes; with a custom image=, background processes are off by defaulta Docker daemon and the docker package
BashkitSandboxshell and file work without Python or gitnothe bashkit extra
DangerousLocalSandboxlocal development and CI, with no isolationyesALLOW_DANGEROUS_LOCAL_HOST=1

The local sandboxes need no cloud_user role.

BashkitSandbox runs the model's commands in your own process, with weaker isolation than a container, so use it only on trusted input.

Sandbox access

access sets the sandbox tools the model gets. "files" keeps read_file, write_file and edit and removes bash:

agent = agents.Agent(model="mistral-large-4", environment=agents.MistralSandbox(access="files"))

Set up the sandbox

Sandbox setup
illustrationWindow

Sandbox setup

Install tools, and set a git identity.

Sandbox hooks
illustrationRobot

Sandbox hooks

Seed the workspace, and save what the agent produced.

Network access
illustrationBarrier

Network access

Set what can leave the sandbox.

Next

Mistral sandbox: the cloud_user role, size and lifetime.