Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"Deploying an Environment","local":"deploying-an-environment","sections":[{"title":"Dependencies and Dockerfile","local":"dependencies-and-dockerfile","sections":[],"depth":2},{"title":"Build the image","local":"build-the-image","sections":[],"depth":2},{"title":"Validate","local":"validate","sections":[],"depth":2},{"title":"Push to Hugging Face Spaces","local":"push-to-hugging-face-spaces","sections":[{"title":"Declare public variables in openenv.yaml","local":"declare-public-variables-in-openenvyaml","sections":[],"depth":3}],"depth":2},{"title":"Use the deployed environment","local":"use-the-deployed-environment","sections":[],"depth":2},{"title":"Build in CI (OpenEnv repo only)","local":"build-in-ci-openenv-repo-only","sections":[],"depth":2}],"depth":1}"/> | |
| <link href="/docs/openenv/pr_1285/en/_app/immutable/entry/start.CG5FzNt2.js" rel="modulepreload"> | |
| <link href="/docs/openenv/pr_1285/en/_app/immutable/chunks/BBXg17tp.js" rel="modulepreload"> | |
| <link href="/docs/openenv/pr_1285/en/_app/immutable/chunks/BSuxAqoA.js" rel="modulepreload"> | |
| <link href="/docs/openenv/pr_1285/en/_app/immutable/entry/app.Db-H8-tM.js" rel="modulepreload"> | |
| <link href="/docs/openenv/pr_1285/en/_app/immutable/chunks/Ds_1Ru_R.js" rel="modulepreload"> | |
| <link href="/docs/openenv/pr_1285/en/_app/immutable/chunks/DIlRkxSv.js" rel="modulepreload"> | |
| <link href="/docs/openenv/pr_1285/en/_app/immutable/chunks/DsnmJJEf.js" rel="modulepreload"> | |
| <link href="/docs/openenv/pr_1285/en/_app/immutable/chunks/BAUKCucN.js" rel="modulepreload"> | |
| <link href="/docs/openenv/pr_1285/en/_app/immutable/nodes/0.CR0SH4Os.js" rel="modulepreload"> | |
| <link href="/docs/openenv/pr_1285/en/_app/immutable/chunks/CR5HsSXT.js" rel="modulepreload"> | |
| <link href="/docs/openenv/pr_1285/en/_app/immutable/nodes/46.D_wqBihq.js" rel="modulepreload"> | |
| <link href="/docs/openenv/pr_1285/en/_app/immutable/chunks/C07d6Hje.js" rel="modulepreload"> | |
| <!--19zve3l--><meta name="hf:doc:metadata" content="{"title":"Deploying an Environment","local":"deploying-an-environment","sections":[{"title":"Dependencies and Dockerfile","local":"dependencies-and-dockerfile","sections":[],"depth":2},{"title":"Build the image","local":"build-the-image","sections":[],"depth":2},{"title":"Validate","local":"validate","sections":[],"depth":2},{"title":"Push to Hugging Face Spaces","local":"push-to-hugging-face-spaces","sections":[{"title":"Declare public variables in openenv.yaml","local":"declare-public-variables-in-openenvyaml","sections":[],"depth":3}],"depth":2},{"title":"Use the deployed environment","local":"use-the-deployed-environment","sections":[],"depth":2},{"title":"Build in CI (OpenEnv repo only)","local":"build-in-ci-openenv-repo-only","sections":[],"depth":2}],"depth":1}"/><!----> | |
| <link href="/docs/openenv/pr_1285/en/_app/immutable/assets/0.tn0RQdqM.css" rel="modulepreload"> <!--[--><!--[0--><!--[--><!--[0--><!--[--><p></p> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"><div class="inline-flex rounded-md max-sm:rounded-sm"><button class="inline-flex items-center gap-1 h-7 max-sm:h-7 px-2 max-sm:px-1.5 text-sm font-medium text-gray-800 border border-r-0 rounded-l-md max-sm:rounded-l-sm border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-live="polite"><span class="inline-flex items-center justify-center rounded-md p-0.5 max-sm:p-0 hover:text-gray-800 dark:hover:text-gray-200"><svg class="sm:size-3.5 size-3" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----></span> <span>Copy page</span></button> <button class="inline-flex items-center justify-center w-6 max-sm:w-5 h-7 max-sm:h-7 disabled:pointer-events-none text-sm text-gray-500 hover:text-gray-700 dark:hover:text-white rounded-r-md max-sm:rounded-r-sm border border-l transition border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-haspopup="menu" aria-expanded="false" aria-label="Open copy menu"><svg class="transition-transform text-gray-400 overflow-visible sm:size-3.5 size-3 rotate-0" width="1em" height="1em" viewBox="0 0 12 7" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L6 6L11 1" stroke="currentColor"></path></svg><!----></button></div> <!--[-1--><!--]--></div><!----> <!--[0--><h1 class="relative group"><a id="deploying-an-environment" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#deploying-an-environment"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Deploying an Environment</span></h1><!--]--><!----> <p>This page covers packaging and sharing an environment once it runs locally: dependencies and the Dockerfile, <code>openenv build</code>, <code>openenv validate</code>, <code>openenv push</code> and connecting to the deployed environment. To create the environment first, follow <a href="../guides/first-environment">Your First Environment</a>.</p> <table><thead><tr><th>Command</th><th>Description</th></tr></thead><tbody><tr><td><code>openenv build</code></td><td>Build the Docker image locally</td></tr><tr><td><code>openenv validate --level static --skip-build</code></td><td>Validate the manifest contract in <code>openenv.yaml</code></td></tr><tr><td><code>openenv push</code></td><td>Deploy to a Hugging Face Space</td></tr><tr><td><code>openenv push --repo-id NAME</code></td><td>Deploy to a specific Space</td></tr><tr><td><code>openenv push --private</code></td><td>Deploy as a private Space</td></tr><tr><td><code>openenv push --registry ghcr.io/ORG</code></td><td>Push the image to a Docker registry instead</td></tr></tbody></table> <p>See the <a href="../reference/cli">CLI reference</a> for every command and flag.</p> <!--[1--><h2 class="relative group"><a id="dependencies-and-dockerfile" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#dependencies-and-dockerfile"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Dependencies and Dockerfile</span></h2><!--]--><!----> <p>Declare Python dependencies in the environment’s <code>pyproject.toml</code> and regenerate <code>uv.lock</code> with <code>uv lock</code>. Install anything else (system packages, binaries) in <code>server/Dockerfile</code>, before the step that removes temporary files.</p> <p>The template’s <a href="https://github.com/huggingface/OpenEnv/blob/main/src/openenv/cli/templates/openenv_env/server/Dockerfile" rel="nofollow"><code>server/Dockerfile</code></a> is a multi-stage build on <code>ghcr.io/huggingface/openenv-base</code> that installs your dependencies with <code>uv sync</code> and serves <code>server.app:app</code> on port 8000. Keep building from <code>openenv-base</code> so shared tooling stays available.</p> <!--[1--><h2 class="relative group"><a id="build-the-image" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#build-the-image"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Build the image</span></h2><!--]--><!----> <p>From the environment folder (needs Docker):</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-bash "><!---->openenv build<!----></pre></div><!----> <p><code>openenv build</code> works for standalone environments and for ones inside the OpenEnv repo, and sets the build arguments accordingly. Useful flags:</p> <ul><li><code>--tag/-t</code>: override the default tag, <code>openenv-<env_name></code> without its <code>_env</code> suffix (<code>openenv-my</code> for <code>my_env</code>)</li> <li><code>--build-arg KEY=VALUE</code>: pass Docker build arguments (repeatable)</li> <li><code>--dockerfile/-f</code> / <code>--context/-c</code>: custom locations when experimenting</li> <li><code>--no-cache</code>: force fresh dependency installs</li></ul> <!--[1--><h2 class="relative group"><a id="validate" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#validate"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Validate</span></h2><!--]--><!----> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-bash "><!---->openenv validate --level static --skip-build<!----></pre></div><!----> <p><code>openenv validate</code> reads the <code>validation:</code> contract in <code>openenv.yaml</code>, checks the normalized manifest against the selected severity policy and exits non-zero when a required check fails. The report’s <code>levels_run</code> field records which levels ran. To validate a running server, use <code>openenv validate --url http://localhost:8000</code>.</p> <!--[1--><h2 class="relative group"><a id="push-to-hugging-face-spaces" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#push-to-hugging-face-spaces"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Push to Hugging Face Spaces</span></h2><!--]--><!----> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-bash "><!----><span class="hljs-comment"># Push the environment in the current folder to <your-username>/<env_name></span> | |
| openenv push | |
| <span class="hljs-comment"># Push to a specific repo or namespace</span> | |
| openenv push --repo-id my-org/my-env | |
| <span class="hljs-comment"># Push to a Docker registry (web UI disabled by default)</span> | |
| openenv push --registry ghcr.io/my-org | |
| <span class="hljs-comment"># Override the base image and make the Space private</span> | |
| openenv push --base-image ghcr.io/huggingface/openenv-base:latest --private | |
| <span class="hljs-comment"># Set Space variables and secrets at push time</span> | |
| openenv push -e OPENSPIEL_GAME=tic_tac_toe --secret OPENAI_API_KEY=sk-...<!----></pre></div><!----> <p>Options:</p> <ul><li><code>DIRECTORY</code> (positional): path to the environment (defaults to the current directory)</li> <li><code>--repo-id/-r</code>: Space name, as <code>name</code> or <code>namespace/name</code></li> <li><code>--registry</code>: push the image to Docker Hub, GHCR, etc.</li> <li><code>--interface/--no-interface</code>: toggle the web UI (on by default for Spaces)</li> <li><code>--base-image/-b</code>: override the Dockerfile <code>FROM</code></li> <li><code>--private</code>: make the Space private</li> <li><code>--env-var/-e KEY=VALUE</code>: set a public Space variable (repeatable), overriding matching keys from <code>variables:</code> in <code>openenv.yaml</code></li> <li><code>--secret KEY=VALUE</code>: set a private Space secret (repeatable). The value is never logged</li> <li><code>--hardware/-H</code>: Space hardware (for example <code>t4-medium</code>)</li> <li><code>--count/-n</code>: deploy several Space instances, each with a numeric suffix</li> <li><code>--create-pr</code>: open a Pull Request instead of pushing to the default branch</li> <li><code>--exclude</code>: an ignore file with globs to leave out of the upload</li> <li><code>--delete <pattern></code>: delete matching remote Space files that are not uploaded again (repeatable), as in <code>hf upload --delete</code></li></ul> <p>The command logs you in if needed, validates <code>openenv.yaml</code>, adds the Hugging Face frontmatter to the README when needed and uploads the bundle. Like <code>hf upload</code>, it never deletes remote files on its own. Pass <code>--delete <pattern></code> (repeatable) to remove matching Space files that are not uploaded again, e.g. <code>--delete "*"</code> to make the Space match the bundle exactly. Local build artifacts (<code>build/</code>, <code>*.egg-info</code>, <code>__pycache__</code>, dotfiles) are never uploaded.</p> <p>Space variables and secrets are only applied on direct Hugging Face Space pushes. They are not available with <code>--registry</code> and cannot be staged through <code>--create-pr</code>.</p> <!--[2--><h3 class="relative group"><a id="declare-public-variables-in-openenvyaml" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#declare-public-variables-in-openenvyaml"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Declare public variables in openenv.yaml</span></h3><!--]--><!----> <p>Defaults that belong with the environment (game name, benchmark, max steps) go in a <code>variables:</code> block in <code>openenv.yaml</code>. <code>openenv push</code> applies them to the Space:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-yaml "><!----><span class="hljs-attr">variables:</span> | |
| <span class="hljs-attr">OPENSPIEL_GAME:</span> <span class="hljs-string">catch</span><!----></pre></div><!----> <p>CLI <code>-e</code> overrides matching keys. Put secrets (API keys, tokens) only on the CLI with <code>--secret KEY=VALUE</code>, never in the yaml.</p> <p>To fork or update someone else’s environment, see <a href="contributing-envs">Contributing Environments</a>.</p> <!--[1--><h2 class="relative group"><a id="use-the-deployed-environment" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#use-the-deployed-environment"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Use the deployed environment</span></h2><!--]--><!----> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">from</span> my_env <span class="hljs-keyword">import</span> MyAction, MyEnv | |
| <span class="hljs-comment"># Pull the Space's image and run it locally (needs Docker)</span> | |
| client = MyEnv.from_env(<span class="hljs-string">"my-org/my-env"</span>).sync() | |
| <span class="hljs-comment"># Or start a container from a local image</span> | |
| client = MyEnv.from_docker_image(<span class="hljs-string">"openenv-my:latest"</span>).sync() | |
| <span class="hljs-comment"># Or connect to a server that is already running</span> | |
| client = MyEnv(base_url=<span class="hljs-string">"http://localhost:8000"</span>).sync() | |
| <span class="hljs-keyword">with</span> client: | |
| result = client.reset() | |
| result = client.step(MyAction(message=<span class="hljs-string">"Hello!"</span>)) | |
| state = client.state()<!----></pre></div><!----> <p><code>from_docker_image()</code> and <code>from_env()</code> return a lazy bootstrap handle, not a connected client. Nothing starts until you resolve it: chain <code>.sync()</code> for a synchronous client, or <code>await</code> the handle from async code. Using the handle directly in a <code>with</code> block raises <code>TypeError: '_BootstrapResult' object does not support the context manager protocol</code>.</p> <p>The async version:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">import</span> asyncio | |
| <span class="hljs-keyword">from</span> my_env <span class="hljs-keyword">import</span> MyAction, MyEnv | |
| <span class="hljs-keyword">async</span> <span class="hljs-keyword">def</span> <span class="hljs-title function_">main</span>(): | |
| client = <span class="hljs-keyword">await</span> MyEnv.from_docker_image(<span class="hljs-string">"openenv-my:latest"</span>) | |
| <span class="hljs-keyword">async</span> <span class="hljs-keyword">with</span> client: | |
| result = <span class="hljs-keyword">await</span> client.reset() | |
| result = <span class="hljs-keyword">await</span> client.step(MyAction(message=<span class="hljs-string">"Hello!"</span>)) | |
| asyncio.run(main())<!----></pre></div><!----> <p>See <a href="../guides/async-sync">Async vs Sync</a> for when to prefer each style and <a href="../guides/runtime-providers">Runtime Providers</a> to run the image somewhere other than local Docker.</p> <!--[1--><h2 class="relative group"><a id="build-in-ci-openenv-repo-only" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#build-in-ci-openenv-repo-only"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span>Build in CI (OpenEnv repo only)</span></h2><!--]--><!----> <p>For an environment inside the OpenEnv repo, add it to the matrix in <code>.github/workflows/docker-build.yml</code> to build its image on every push to <code>main</code>:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Copied</div><!----></button><!----></div> <pre class="language-yaml "><!----><span class="hljs-attr">strategy:</span> | |
| <span class="hljs-attr">matrix:</span> | |
| <span class="hljs-attr">image:</span> | |
| <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">echo-env</span> | |
| <span class="hljs-attr">dockerfile:</span> <span class="hljs-string">envs/echo_env/server/Dockerfile</span> | |
| <span class="hljs-attr">context:</span> <span class="hljs-string">envs/echo_env</span> | |
| <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">my-env</span> <span class="hljs-comment"># Add your environment here</span> | |
| <span class="hljs-attr">dockerfile:</span> <span class="hljs-string">envs/my_env/server/Dockerfile</span> | |
| <span class="hljs-attr">context:</span> <span class="hljs-string">envs/my_env</span><!----></pre></div><!----> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/openenv/blob/main/docs/source/getting_started/environment-builder.md" target="_blank"><svg class="mr-1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M31,16l-7,7l-1.41-1.41L28.17,16l-5.58-5.59L24,9l7,7z"></path><path d="M1,16l7-7l1.41,1.41L3.83,16l5.58,5.59L8,23l-7-7z"></path><path d="M12.419,25.484L17.639,6.552l1.932,0.518L14.351,26.002z"></path></svg><!----> <span><span class="underline">Update</span> on GitHub</span></a><!----> <p></p><!--]--><!----><!--]--><!--]--><!--]--> <!--[-1--><!--]--><!--]--> | |
| <script> | |
| { | |
| __sveltekit_efhe5s = { | |
| base: "/docs/openenv/pr_1285/en", | |
| assets: "/docs/openenv/pr_1285/en" | |
| }; | |
| const element = document.currentScript.parentElement; | |
| Promise.all([ | |
| import("/docs/openenv/pr_1285/en/_app/immutable/entry/start.CG5FzNt2.js"), | |
| import("/docs/openenv/pr_1285/en/_app/immutable/entry/app.Db-H8-tM.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 46], | |
| data: [null,null], | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 34.4 kB
- Xet hash:
- f47b4421dfede1077bcee6563a6d6fed6248dda48ad865efb5be321b9738a3a1
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.