- Studio
- Managed Agents
- Learn
Environment
Environment
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 |
|---|---|---|---|
| NoSandbox | agents that only call tools and connectors | no | nothing |
| MistralSandbox | deployed agents, and any agent that runs untrusted code | yes; with a custom image, background processes are off by default | the sandbox extra and the cloud_user role |
| LocalDockerSandbox | local development and CI | yes; with a custom image=, background processes are off by default | a Docker daemon and the docker package |
| BashkitSandbox | shell and file work without Python or git | no | the bashkit extra |
| DangerousLocalSandbox | local development and CI, with no isolation | yes | ALLOW_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
Install tools, and set a git identity.
Sandbox hooks
Seed the workspace, and save what the agent produced.
Network access
Set what can leave the sandbox.
Next
Mistral sandbox: the cloud_user role, size and lifetime.